Using .eachParallel in a Spock Spy'd class hangs

108 views
Skip to first unread message

Kevin Dorff

unread,
Feb 2, 2017, 5:47:40 PM2/2/17
to GPars Users
Hi,

I tried to search Google (and here) for others reporting this or a similar problem but had no obvious success.

I am attempting to write Spock unit tests for a class which contains a method that contains .eachParallel run within a GParsPool.withPool stanza. It seems that if I Spy the class (similar to Mock, so I can do partial mocking of the class) any calls to .eachParallel will hang the test suite.

I have created a simple example and set of simple Spock test cases which demonstrate what I am seeing (and that if I call .each instead of .eachParallel it works just fine).
In my repo, the failing test cases are marked as @Ignore because they will, for me, reliably hang the test suite.


Any opinions, suggestions, or thoughts are welcome.

Thanks,
Kevin

Russel Winder

unread,
Feb 3, 2017, 10:06:16 AM2/3/17
to gpars...@googlegroups.com
On Thu, 2017-02-02 at 14:47 -0800, Kevin Dorff wrote:
> Hi,
>
> I tried to search Google (and here) for others reporting this or a
> similar 
> problem but had no obvious success.

Google is not the fount of all knowledge, only much of it. ;-)

> I am attempting to write Spock unit tests for a class which contains
> a 
> method that contains .eachParallel run within a GParsPool.withPool
> stanza. 
> It seems that if I Spy the class (similar to Mock, so I can do
> partial 
> mocking of the class) any calls to .eachParallel will hang the test
> suite.

So there are two players here Spy and GPars…

> I have created a simple example and set of simple Spock test cases
> which 
> demonstrate what I am seeing (and that if I call .each instead of 
> .eachParallel it works just fine). 
> In my repo, the failing test cases are marked as *@Ignore* because
> they 
> will, for me, reliably hang the test suite.
>
> https://github.com/kdorff/SpiesAndGpars
>
> Any opinions, suggestions, or thoughts are welcome.

… given the test "Test with calc as spy, add a number and a list of
numbers (parallel)" works fine if I replace:

 calc = Spy(Calc)

with

 calc = new Calc()

the the Spy class is doing something that is incompatible with GPars
threadpool. I think there is a deadlock occurring. Since the tests work
without the Spy proxy, it isn't a GPars problem it's a Spy problem: Spy
is not a transparent proxy as you are trying to use it.

On a more constructive, rather than blame assigning note, I am not sure
how we can progress this with any speed, at least from the GPars end.
Towards the end of this month I had been hoping to get GPars 2.0
released (basically GPars 1.3.0-SNAPSHOT but with all the ParallelArray
stuff removed). It is not clear just at the moment if GPars 1.3.0 will
ever be released.

It is not entirely clear just now if eachParallel will exist in GPars
2.0, especially since Stream.forEach exists – it is not clear if the
old GPars API should be preserved or whether people should just use
Streams things directly.

In this case, constructing an array by side effect as being done here
is probably a bad design – at least as shown here. However that may be
the nature of the strip down. The reasons this is bad code are many
and varied, and require a separate essay. :-)

--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc

Kevin Dorff

unread,
Feb 3, 2017, 1:22:14 PM2/3/17
to GPars Users
Thank you for your quick response. 

I added the option in my class and tests to use the java Executor fixed pool to my code and it seems to hang in the same way. I agree this points back to the problem being something with Spy objects in Spock and thread pools. I will post there with my findings.

Thanks again,
Kevin

Russel Winder

unread,
Feb 4, 2017, 12:21:21 PM2/4/17
to Kevin Dorff, GPars Users
On Fri, 2017-02-03 at 10:22 -0800, Kevin Dorff wrote:
> Thank you for your quick response. 

No problem.

> I added the option in my class and tests to use the java Executor
> fixed 
> pool to my code and it seems to hang in the same way. I agree this
> points 
> back to the problem being something with Spy objects in Spock and
> thread 
> pools. I will post there with my findings.

If you get a resolution, and I hope you get one and quickly, do let us
know.
signature.asc
Reply all
Reply to author
Forward
0 new messages