diff --git a/spock-core/src/main/java/org/spockframework/runtime/PlatformSpecRunner.java b/spock-core/src/main/java/org/spockframework/runtime/PlatformSpecRunner.java index c81cec5f02..5b44c61658 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/PlatformSpecRunner.java +++ b/spock-core/src/main/java/org/spockframework/runtime/PlatformSpecRunner.java @@ -87,7 +87,9 @@ SpockExecutionContext createSpecInstance(SpockExecutionContext context, boolean context = context.withChildStoreProvider().withCurrentInstance(instance); getSpecificationContext(context).setCurrentSpec(context.getSpec()); - getSpecificationContext(context).pushStoreProvider(context.getStoreProvider()); + + // this is either for the shared spec instance or the current iteration + getSpecificationContext(context).setStoreProvider(context.getStoreProvider()); if (shared) { context = context.withSharedInstance(instance); } @@ -193,14 +195,11 @@ public void runFeature(SpockExecutionContext context, Runnable feature) { // so the current feature cannot be set as features can run in parallel // so getting the current feature from the specification context would not properly work - getSpecificationContext(context).pushStoreProvider(context.getStoreProvider()); - supervisor.beforeFeature(currentFeature); invoke(context, this, createMethodInfoForDoRunFeature(context, feature)); supervisor.afterFeature(currentFeature); runCloseContextStoreProvider(context, MethodKind.CLEANUP); - getSpecificationContext(context).popStoreProvider(); } private MethodInfo createMethodInfoForDoRunFeature(SpockExecutionContext context, Runnable feature) { @@ -222,15 +221,11 @@ void runIteration(SpockExecutionContext context, IterationInfo iterationInfo, Ru context = context.withCurrentIteration(iterationInfo); getSpecificationContext(context).setCurrentIteration(iterationInfo); - getSpecificationContext(context).pushStoreProvider(context.getStoreProvider()); supervisor.beforeIteration(iterationInfo); invoke(context, this, createMethodInfoForDoRunIteration(context, runnable)); supervisor.afterIteration(iterationInfo); runCloseContextStoreProvider(context, MethodKind.CLEANUP); - - getSpecificationContext(context).setCurrentIteration(null); // TODO check if we really need to null here - getSpecificationContext(context).popStoreProvider(); } IterationInfo createIterationInfo(SpockExecutionContext context, int iterationIndex, Object[] args, int estimatedNumIterations) { diff --git a/spock-core/src/main/java/org/spockframework/runtime/SpecificationContext.java b/spock-core/src/main/java/org/spockframework/runtime/SpecificationContext.java index d250afc157..af58d3b427 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/SpecificationContext.java +++ b/spock-core/src/main/java/org/spockframework/runtime/SpecificationContext.java @@ -22,7 +22,7 @@ public class SpecificationContext implements ISpecificationContext { private volatile Specification sharedInstance; private volatile Throwable thrownException; - private final Deque storeProvider = new ArrayDeque<>(3); // spec, feature, iteration + private volatile IStoreProvider storeProvider; // shared spec or iteration private final MockController mockController = new MockController(); @@ -113,14 +113,10 @@ public IThreadAwareMockController getThreadAwareMockController() { @Override public IStore getStore(IStore.Namespace namespace) { - return storeProvider.getLast().getStore(namespace); + return storeProvider.getStore(namespace); } - public void pushStoreProvider(IStoreProvider storeProvider) { - this.storeProvider.push(storeProvider); - } - - public void popStoreProvider() { - this.storeProvider.pop(); + public void setStoreProvider(IStoreProvider storeProvider) { + this.storeProvider = storeProvider; } }