{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Home/issues/1541","repository_url":"https://api.github.com/repos/aspnet/Home","labels_url":"https://api.github.com/repos/aspnet/Home/issues/1541/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Home/issues/1541/comments","events_url":"https://api.github.com/repos/aspnet/Home/issues/1541/events","html_url":"https://github.com/aspnet/Home/issues/1541","id":158420431,"number":1541,"title":"Multiple TestServer instances seem to be sharing a context / seem to be pointing to the same server.","user":{"login":"Yablargo","id":4755200,"avatar_url":"https://avatars.githubusercontent.com/u/4755200?v=3","gravatar_id":"","url":"https://api.github.com/users/Yablargo","html_url":"https://github.com/Yablargo","followers_url":"https://api.github.com/users/Yablargo/followers","following_url":"https://api.github.com/users/Yablargo/following{/other_user}","gists_url":"https://api.github.com/users/Yablargo/gists{/gist_id}","starred_url":"https://api.github.com/users/Yablargo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yablargo/subscriptions","organizations_url":"https://api.github.com/users/Yablargo/orgs","repos_url":"https://api.github.com/users/Yablargo/repos","events_url":"https://api.github.com/users/Yablargo/events{/privacy}","received_events_url":"https://api.github.com/users/Yablargo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-06-03T17:55:59Z","updated_at":"2016-06-06T21:40:12Z","closed_at":null,"body":"Hello. I have a number of Integration Tests that use a shared TestServer instance and a TestStartup class extended from Startup that contains a Seed() method and uses InMemoryDatabase.\r\n\r\nIn dnx / RC1, all of my tests passed without issues. \r\n\r\nI have a subset of the tests that launch a separate (clean) server and tests initial database values before the rest start fiddling with things.\r\n\r\nWhen I upgraded to RC2, I use this to launch my test server\r\n\r\n`Server = new TestServer(new WebHostBuilder().UseContentRoot(System.IO.Directory.GetCurrentDirectory()).UseStartup<TestStartup>());`\r\n\r\nBut what I find now is that if i run my tests by themselves, they pass, but when I run them together simultaniously, my separate TestServers get the same contexts.\r\n\r\nIs there a way I can scope my Context such that I get a new one for each TestServer instance?\r\nI'm getting my context in the Seed() -- called from Configure() like so:\r\n\r\n`  var db = app.ApplicationServices.GetService<ApplicationDbContext>();`\r\n\r\nand it seems somewhat obvious that my app already has a context and returns the same instance"},"comment":{"url":"https://api.github.com/repos/aspnet/Home/issues/comments/224096953","html_url":"https://github.com/aspnet/Home/issues/1541#issuecomment-224096953","issue_url":"https://api.github.com/repos/aspnet/Home/issues/1541","id":224096953,"user":{"login":"Tratcher","id":1821173,"avatar_url":"https://avatars.githubusercontent.com/u/1821173?v=3","gravatar_id":"","url":"https://api.github.com/users/Tratcher","html_url":"https://github.com/Tratcher","followers_url":"https://api.github.com/users/Tratcher/followers","following_url":"https://api.github.com/users/Tratcher/following{/other_user}","gists_url":"https://api.github.com/users/Tratcher/gists{/gist_id}","starred_url":"https://api.github.com/users/Tratcher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tratcher/subscriptions","organizations_url":"https://api.github.com/users/Tratcher/orgs","repos_url":"https://api.github.com/users/Tratcher/repos","events_url":"https://api.github.com/users/Tratcher/events{/privacy}","received_events_url":"https://api.github.com/users/Tratcher/received_events","type":"User","site_admin":false},"created_at":"2016-06-06T21:40:12Z","updated_at":"2016-06-06T21:40:12Z","body":"Sharing a TestServer instance statically across tests is not a good idea for unit tests. There's too much of a risk that the tests can have side-effects on eachother. Note xunit can execute tests in parallel, but by default it will only do this for tests in different classes.\r\n\r\nI doubt you're getting the same DbContext instance, but you may be connecting to the same in-memory database.  @bricelam does UseInMemoryDatabase create a single static instance in memory that may be inadvertently shared across unit tests?"}}
{"actor":{"display_login":"Tratcher"}}