From 0e880336c4ac833b54e48ad84834164f8cdce2df Mon Sep 17 00:00:00 2001 From: Gregory Haskins Date: Sun, 31 Jan 2016 23:34:42 -0500 Subject: [PATCH] Add some thread safety defense MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To make sure only one definition block can run at a time so that global `describe` and `it` functions don’t get mis-attached. --- src/main/java/com/greghaskins/spectrum/Spectrum.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/greghaskins/spectrum/Spectrum.java b/src/main/java/com/greghaskins/spectrum/Spectrum.java index 45a9542..d79dfcf 100644 --- a/src/main/java/com/greghaskins/spectrum/Spectrum.java +++ b/src/main/java/com/greghaskins/spectrum/Spectrum.java @@ -146,7 +146,7 @@ public void run(final RunNotifier notifier) { this.rootSuite.run(notifier); } - private static void beginDefintion(final Suite suite, final Block definitionBlock) { + synchronized private static void beginDefintion(final Suite suite, final Block definitionBlock) { suiteStack.push(suite); try { definitionBlock.run(); @@ -156,7 +156,7 @@ private static void beginDefintion(final Suite suite, final Block definitionBloc suiteStack.pop(); } - private static Suite getCurrentSuite() { + synchronized private static Suite getCurrentSuite() { return suiteStack.peek(); }