{"action":"created","issue":{"url":"https://api.github.com/repos/techtalk/SpecFlow/issues/638","repository_url":"https://api.github.com/repos/techtalk/SpecFlow","labels_url":"https://api.github.com/repos/techtalk/SpecFlow/issues/638/labels{/name}","comments_url":"https://api.github.com/repos/techtalk/SpecFlow/issues/638/comments","events_url":"https://api.github.com/repos/techtalk/SpecFlow/issues/638/events","html_url":"https://github.com/techtalk/SpecFlow/issues/638","id":157797427,"number":638,"title":"SpecFlow incorrectly assumes tests are multi-threaded if test runner is re-used under NUnit3","user":{"login":"remcomulder","id":845496,"avatar_url":"https://avatars.githubusercontent.com/u/845496?v=3","gravatar_id":"","url":"https://api.github.com/users/remcomulder","html_url":"https://github.com/remcomulder","followers_url":"https://api.github.com/users/remcomulder/followers","following_url":"https://api.github.com/users/remcomulder/following{/other_user}","gists_url":"https://api.github.com/users/remcomulder/gists{/gist_id}","starred_url":"https://api.github.com/users/remcomulder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remcomulder/subscriptions","organizations_url":"https://api.github.com/users/remcomulder/orgs","repos_url":"https://api.github.com/users/remcomulder/repos","events_url":"https://api.github.com/users/remcomulder/events{/privacy}","received_events_url":"https://api.github.com/users/remcomulder/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/techtalk/SpecFlow/labels/Green","name":"Green","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"SabotageAndi","id":859801,"avatar_url":"https://avatars.githubusercontent.com/u/859801?v=3","gravatar_id":"","url":"https://api.github.com/users/SabotageAndi","html_url":"https://github.com/SabotageAndi","followers_url":"https://api.github.com/users/SabotageAndi/followers","following_url":"https://api.github.com/users/SabotageAndi/following{/other_user}","gists_url":"https://api.github.com/users/SabotageAndi/gists{/gist_id}","starred_url":"https://api.github.com/users/SabotageAndi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SabotageAndi/subscriptions","organizations_url":"https://api.github.com/users/SabotageAndi/orgs","repos_url":"https://api.github.com/users/SabotageAndi/repos","events_url":"https://api.github.com/users/SabotageAndi/events{/privacy}","received_events_url":"https://api.github.com/users/SabotageAndi/received_events","type":"User","site_admin":false},"assignees":[{"login":"SabotageAndi","id":859801,"avatar_url":"https://avatars.githubusercontent.com/u/859801?v=3","gravatar_id":"","url":"https://api.github.com/users/SabotageAndi","html_url":"https://github.com/SabotageAndi","followers_url":"https://api.github.com/users/SabotageAndi/followers","following_url":"https://api.github.com/users/SabotageAndi/following{/other_user}","gists_url":"https://api.github.com/users/SabotageAndi/gists{/gist_id}","starred_url":"https://api.github.com/users/SabotageAndi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SabotageAndi/subscriptions","organizations_url":"https://api.github.com/users/SabotageAndi/orgs","repos_url":"https://api.github.com/users/SabotageAndi/repos","events_url":"https://api.github.com/users/SabotageAndi/events{/privacy}","received_events_url":"https://api.github.com/users/SabotageAndi/received_events","type":"User","site_admin":false},{"login":"samholder","id":2073290,"avatar_url":"https://avatars.githubusercontent.com/u/2073290?v=3","gravatar_id":"","url":"https://api.github.com/users/samholder","html_url":"https://github.com/samholder","followers_url":"https://api.github.com/users/samholder/followers","following_url":"https://api.github.com/users/samholder/following{/other_user}","gists_url":"https://api.github.com/users/samholder/gists{/gist_id}","starred_url":"https://api.github.com/users/samholder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samholder/subscriptions","organizations_url":"https://api.github.com/users/samholder/orgs","repos_url":"https://api.github.com/users/samholder/repos","events_url":"https://api.github.com/users/samholder/events{/privacy}","received_events_url":"https://api.github.com/users/samholder/received_events","type":"User","site_admin":false}],"milestone":null,"comments":25,"created_at":"2016-06-01T00:09:16Z","updated_at":"2016-07-27T10:20:11Z","closed_at":null,"body":"Hi, NCrunch developer here.\r\n\r\nI've had reported to me a problem in which SpecFlow kicks up an error when NCrunch is used to run specifications under NUnit3 with single-threaded execution:\r\n\r\nTechTalk.SpecFlow.SpecFlowException : The ScenarioContext.Current static accessor cannot be used in multi-threaded execution. Try injecting the scenario context to the binding class. See http://go.specflow.org/doc-multithreaded for details.\r\n   at TechTalk.SpecFlow.ScenarioContext.get_Current()\r\n   at SpecFlow2NUnit3NCrunch.CustomContext.ScenarioSetUp() in C:\\Temp\\SpecFlow2NCrunchProblem\\SpecFlow2NUnit3NCrunch\\CustomContext.cs:line 14\r\n   at lambda_method(Closure , IContextManager )\r\n   at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)\r\n   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType bindingEvent)\r\n   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioStart(ScenarioInfo scenarioInfo)\r\n   at TechTalk.SpecFlow.TestRunner.OnScenarioStart(ScenarioInfo scenarioInfo)\r\n   at SpecFlow2NUnit3NCrunch.CalculateFeature.ScenarioSetup(ScenarioInfo scenarioInfo) in C:\\Temp\\SpecFlow2NCrunchProblem\\SpecFlow2NUnit3NCrunch\\CalculatorTest.feature.cs:line 0\r\n   at SpecFlow2NUnit3NCrunch.CalculateFeature.MultiplyTwoNumbers(String case, String a, String b, String result, String[] exampleTags) in C:\\Temp\\SpecFlow2NCrunchProblem\\SpecFlow2NUnit3NCrunch\\CalculatorTest.feature:line 29\r\n\r\nThe cause of the problem seems to be in the TechTalk.SpecFlow.TestRunnerManager class, where SpecFlow attempts to identify multi-threaded execution by tracking the IDs of threads used to access the ScenarioContext.  The code doesn't behave as expected in situations where the test runner process is re-used.\r\n\r\nNCrunch can make multiple calls into a test runner for its batching, invoking the test framework multiple times.  The first call into the test framework works fine, but if it calls in again, NUnit3 runs the tests on a different thread and the code throws the above exception.\r\n\r\nThis was never a problem under NUnit2, because NUnit2 would always run tests on the thread used to invoke the framework, and NCrunch always uses the same thread to invoke the framework.  However, NUnit3 introduced significant changes to the threading model and internalises the creation of a new thread for each test run.\r\n\r\nA possible solution to this problem would be to 'reset' the tracking of threads at the start of every test run.\r\n\r\nAlternatively, it is possible to check for the 'NCrunch' environment variable (which equals '1' under an NCrunch test run) and simply suppress the behaviour.  NCrunch always disables the parallel execution features of test frameworks because it handles them at a higher level (across multiple processes).  I presume this solution will be undesirable as it is product-specific and I'm not sure if other test runners are doing the same thing as NCrunch."},"comment":{"url":"https://api.github.com/repos/techtalk/SpecFlow/issues/comments/235546237","html_url":"https://github.com/techtalk/SpecFlow/issues/638#issuecomment-235546237","issue_url":"https://api.github.com/repos/techtalk/SpecFlow/issues/638","id":235546237,"user":{"login":"gasparnagy","id":144701,"avatar_url":"https://avatars.githubusercontent.com/u/144701?v=3","gravatar_id":"","url":"https://api.github.com/users/gasparnagy","html_url":"https://github.com/gasparnagy","followers_url":"https://api.github.com/users/gasparnagy/followers","following_url":"https://api.github.com/users/gasparnagy/following{/other_user}","gists_url":"https://api.github.com/users/gasparnagy/gists{/gist_id}","starred_url":"https://api.github.com/users/gasparnagy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gasparnagy/subscriptions","organizations_url":"https://api.github.com/users/gasparnagy/orgs","repos_url":"https://api.github.com/users/gasparnagy/repos","events_url":"https://api.github.com/users/gasparnagy/events{/privacy}","received_events_url":"https://api.github.com/users/gasparnagy/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T10:20:11Z","updated_at":"2016-07-27T10:20:11Z","body":"@samholder yeah, that could be an easy way to test the concept..."}}
{"actor":{"display_login":"gasparnagy"}}