Skip to content

Commit 2db34b0

Browse files
authored
Fix the IStoreProvider impl. in SpecContext... (#2071)
The `SpecificationContext` always belongs to a single spec instance, so it is either the shared `Specification` instance or it belongs to the iteration. There is no `Feature`-level instance, so we don't need to use a stack.
1 parent b57816a commit 2db34b0

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

spock-core/src/main/java/org/spockframework/runtime/PlatformSpecRunner.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ SpockExecutionContext createSpecInstance(SpockExecutionContext context, boolean
8787

8888
context = context.withChildStoreProvider().withCurrentInstance(instance);
8989
getSpecificationContext(context).setCurrentSpec(context.getSpec());
90-
getSpecificationContext(context).pushStoreProvider(context.getStoreProvider());
90+
91+
// this is either for the shared spec instance or the current iteration
92+
getSpecificationContext(context).setStoreProvider(context.getStoreProvider());
9193
if (shared) {
9294
context = context.withSharedInstance(instance);
9395
}
@@ -193,14 +195,11 @@ public void runFeature(SpockExecutionContext context, Runnable feature) {
193195
// so the current feature cannot be set as features can run in parallel
194196
// so getting the current feature from the specification context would not properly work
195197

196-
getSpecificationContext(context).pushStoreProvider(context.getStoreProvider());
197-
198198
supervisor.beforeFeature(currentFeature);
199199
invoke(context, this, createMethodInfoForDoRunFeature(context, feature));
200200
supervisor.afterFeature(currentFeature);
201201

202202
runCloseContextStoreProvider(context, MethodKind.CLEANUP);
203-
getSpecificationContext(context).popStoreProvider();
204203
}
205204

206205
private MethodInfo createMethodInfoForDoRunFeature(SpockExecutionContext context, Runnable feature) {
@@ -222,15 +221,11 @@ void runIteration(SpockExecutionContext context, IterationInfo iterationInfo, Ru
222221

223222
context = context.withCurrentIteration(iterationInfo);
224223
getSpecificationContext(context).setCurrentIteration(iterationInfo);
225-
getSpecificationContext(context).pushStoreProvider(context.getStoreProvider());
226224

227225
supervisor.beforeIteration(iterationInfo);
228226
invoke(context, this, createMethodInfoForDoRunIteration(context, runnable));
229227
supervisor.afterIteration(iterationInfo);
230228
runCloseContextStoreProvider(context, MethodKind.CLEANUP);
231-
232-
getSpecificationContext(context).setCurrentIteration(null); // TODO check if we really need to null here
233-
getSpecificationContext(context).popStoreProvider();
234229
}
235230

236231
IterationInfo createIterationInfo(SpockExecutionContext context, int iterationIndex, Object[] args, int estimatedNumIterations) {

spock-core/src/main/java/org/spockframework/runtime/SpecificationContext.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SpecificationContext implements ISpecificationContext {
2222
private volatile Specification sharedInstance;
2323

2424
private volatile Throwable thrownException;
25-
private final Deque<IStoreProvider> storeProvider = new ArrayDeque<>(3); // spec, feature, iteration
25+
private volatile IStoreProvider storeProvider; // shared spec or iteration
2626

2727
private final MockController mockController = new MockController();
2828

@@ -113,14 +113,10 @@ public IThreadAwareMockController getThreadAwareMockController() {
113113

114114
@Override
115115
public IStore getStore(IStore.Namespace namespace) {
116-
return storeProvider.getLast().getStore(namespace);
116+
return storeProvider.getStore(namespace);
117117
}
118118

119-
public void pushStoreProvider(IStoreProvider storeProvider) {
120-
this.storeProvider.push(storeProvider);
121-
}
122-
123-
public void popStoreProvider() {
124-
this.storeProvider.pop();
119+
public void setStoreProvider(IStoreProvider storeProvider) {
120+
this.storeProvider = storeProvider;
125121
}
126122
}

0 commit comments

Comments
 (0)