Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ScenarioContext.Current thread safe?

I get the impression that it's not. I have three integration tests that succeed when run individually, but when run in parallel, I get System.ArgumentException: An item with the same key has already been added.

I was sure hoping that ScenarioContext.Current always referred to the correct scenario, but it seems it's getting confused. Has anyone successfully added thread safety to this class? Or is there another approach I should be using for sharing values among step files?

like image 908
Samo Avatar asked Nov 21 '11 21:11

Samo


1 Answers

ScenarioContext.Curent source:

public static ScenarioContext Current
    {
        get
        {
            if (current == null)
            {
                Debug.WriteLine("Accessing NULL ScenarioContext");
            }
            return current;
        }
        internal set { current = value; }
    }

As you can see, it is not threadsafe https://github.com/techtalk/SpecFlow/blob/master/Runtime/ScenarioContext.cs

like image 172
Andrew Avatar answered Oct 06 '22 22:10

Andrew