Forgus / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Stepwise does not work reliably with Java 7 #301

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem? If possible, provide source code and
stack trace.
1. Use Java 7 to compile a project and test with spock
2. Use at least one test with the @Stepwise annotation
3. Run multiple times and observe how the execution order changes randomly.

What version of Spock and Groovy are you using?
Spock 0.6 (didn't see any changes in 0.7), and Groovy 1.8.6.

Please provide any additional information below. You can also assign
labels.

See Oracle's document on Java 7: 
http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#jdk7

Apparently this was "fixed" so that the getDeclaredMethods method on a class 
does not return them in declared order.  This is according to spec, which 
states there is no order, but different from how it was done in Java 6.  I 
can't find a way to replicate the same functionality in a quick google search, 
but in the meantime we've created our own stepwise based on method name and are 
changing our method names to reflect the same order as declared.  This appears 
to be working just fine.

Original issue reported on code.google.com by bsavi...@adaptivecomputing.com on 22 Feb 2013 at 7:41

GoogleCodeExporter commented 8 years ago
Spock doesn't rely on reflection to guarantee that methods of a @Stepwise spec 
are executed in their declared order (which wouldn't work). Instead, it uses 
its Groovy compiler plugin to do so, which is 100% reliable. However, there is 
a known issue that Spock's "optimize run order" feature (which is activated 
with "runner.optimizeRunOrder = true" in SpockConfig.groovy) doesn't currently 
take into account that methods of @Stepwise specs must not be reordered. Is 
that maybe what you are running into?

Original comment by pnied...@gmail.com on 23 Feb 2013 at 12:07

GoogleCodeExporter commented 8 years ago
I thought about the same thing (that optimize run order might be playing with 
it), so we explicitly disabled it even though we never set it to 'true' 
anywhere. So I don't think that's it.

Original comment by bsavi...@adaptivecomputing.com on 23 Feb 2013 at 12:11

GoogleCodeExporter commented 8 years ago
The best way to see what's going on is to debug a spec and set a breakpoint 
somewhere in`org.spockframework.runtime.extension.builtin.StepwiseExtension`. 
In particular, check if `feature.getDeclarationOrder()` (as used in the 
`sortFeaturesInDeclarationOrder` method) returns the correct result. Also note 
that `@Stepwise` currently only affects the methods of the annotated class, not 
those of its super classes.

Original comment by pnied...@gmail.com on 23 Feb 2013 at 12:26

GoogleCodeExporter commented 8 years ago
Also set a breakpoint in 
`org.spockframework.runtime.extension.builtin.OptimizeRunOrderExtension` to see 
if it's ever called.

Original comment by pnied...@gmail.com on 23 Feb 2013 at 12:37

GoogleCodeExporter commented 8 years ago
Also note that there was a regression in 0.6 that led to exactly the problems 
that you are describing (see 
http://code.google.com/p/spock/issues/detail?id=256), but it was fixed in 0.7.

Original comment by pnied...@gmail.com on 23 Feb 2013 at 12:46

GoogleCodeExporter commented 8 years ago
That's definitely it! (the regression).  I searched everywhere and never found 
that one, apparently the search on google code ironically isn't that great. :)  
Thanks, we'll see if we can upgrade.

Original comment by bsavi...@adaptivecomputing.com on 23 Feb 2013 at 12:57

GoogleCodeExporter commented 8 years ago
Should be a drop-in replacement (no known incompatible changes in public APIs). 
Make sure to recompile all specs.

Original comment by pnied...@gmail.com on 23 Feb 2013 at 1:02

GoogleCodeExporter commented 8 years ago
There are some geb incompatabilities if I remember right, but nothing too 
serious.

Original comment by bsavi...@adaptivecomputing.com on 23 Feb 2013 at 1:13

GoogleCodeExporter commented 8 years ago
That's correct. You'll have to update to Geb 0.9.0-RC-1.

Original comment by pnied...@gmail.com on 23 Feb 2013 at 1:20

GoogleCodeExporter commented 8 years ago

Original comment by pnied...@gmail.com on 24 Feb 2013 at 12:33