{"action":"closed","issue":{"url":"https://api.github.com/repos/tornadoweb/tornado/issues/1307","labels_url":"https://api.github.com/repos/tornadoweb/tornado/issues/1307/labels{/name}","comments_url":"https://api.github.com/repos/tornadoweb/tornado/issues/1307/comments","events_url":"https://api.github.com/repos/tornadoweb/tornado/issues/1307/events","html_url":"https://github.com/tornadoweb/tornado/issues/1307","id":55002064,"number":1307,"title":"AsyncTestCase + process.Subprocess = BUG","user":{"login":"socketpair","id":1157412,"avatar_url":"https://avatars.githubusercontent.com/u/1157412?v=3","gravatar_id":"","url":"https://api.github.com/users/socketpair","html_url":"https://github.com/socketpair","followers_url":"https://api.github.com/users/socketpair/followers","following_url":"https://api.github.com/users/socketpair/following{/other_user}","gists_url":"https://api.github.com/users/socketpair/gists{/gist_id}","starred_url":"https://api.github.com/users/socketpair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/socketpair/subscriptions","organizations_url":"https://api.github.com/users/socketpair/orgs","repos_url":"https://api.github.com/users/socketpair/repos","events_url":"https://api.github.com/users/socketpair/events{/privacy}","received_events_url":"https://api.github.com/users/socketpair/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-21T10:34:27Z","updated_at":"2015-01-23T02:48:43Z","closed_at":"2015-01-23T02:48:43Z","body":"Suppose test:\r\n\r\n```\r\n@gen.coroutine\r\ndef async_exec(args, **kwargs):\r\n    kwargs['stdout'] = Subprocess.STREAM\r\n    kwargs['stderr'] = Subprocess.STREAM\r\n    p = Subprocess(args, **kwargs)\r\n    (code, stdout, stderr) = yield [\r\n        Task(p.set_exit_callback),\r\n        p.stdout.read_until_close(),\r\n        p.stderr.read_until_close(),\r\n    ]\r\n    raise gen.Return((code, stdout, stderr))\r\n\r\nclass TestAsyncExec(AsyncTestCase):\r\n    @gen_test\r\n    def test_async_exec(self):\r\n        (code, stdout, stderr) = yield async_exec(['echo', 'teststring'])\r\n        self.assertEqual(code, 0)\r\n        self.assertEqual(stdout, 'teststring\\n')\r\n        self.assertEqual(stderr, '')\r\n```\r\n\r\nThis will SOMETIMES NOT WORKING (!) (race condition). To fix, I should do that:\r\n\r\n```\r\nclass TestAsyncExec(AsyncTestCase):\r\n    def setUp(self):\r\n        super(TestAsyncExec, self).setUp()\r\n        Subprocess.uninitialize() # someone may do initialize() during imports...\r\n        Subprocess.initialize(self.io_loop)\r\n\r\n    def tearDown(self):\r\n        super(TestAsyncExec, self).tearDown()\r\n        Subprocess.uninitialize()\r\n```\r\n\r\nThis is not so obvious. Seems, some changes required to make life of testers easy.\r\n\r\nMaybe integrate that code into AsyncTestCase.setUp()/tearDown()?\r\n\r\n"}}