2012-04-01 15 views
2

Tornado AsyncHTTPTestCaseを使用してテストを実行すると、テストに関連しないスタックトレースが発生します。テストが合格しているので、これはおそらくテストクリーンアップで起こっているでしょうか?Tornado AsyncHTTPTestCaseを実行しているときに不正なファイル記述子を取得しています

私はPython 2.7.2、Tornado 2.2を使用しています。

テストコードは次のとおりです。

class AllServersHandlerTest(AsyncHTTPTestCase): 

    def get_app(self): 
     return Application([('/rest/test/', AllServersHandler)]) 

    def test_server_status_with_advertiser(self): 
     on_new_host(None, '127.0.0.1') 
     response = self.fetch('/rest/test/', method='GET') 
     result = json.loads(response.body, 'utf8').get('data') 
     self.assertEquals(['127.0.0.1'], result) 

テストは、[OK]を渡しますが、私はトルネードサーバーから次のスタックトレースを取得します。

OSError: [Errno 9] Bad file descriptor 
INFO:root:200 POST /rest/serverStatuses (127.0.0.1) 0.00ms 
DEBUG:root:error closing fd 688 
Traceback (most recent call last): 
    File "C:\Python27\Lib\site-packages\tornado-2.2-py2.7.egg\tornado\ioloop.py", line 173, in close 
    os.close(fd) 
OSError: [Errno 9] Bad file descriptor 

どのようにすれば正常にテストケースをシャットダウンできますか?

答えて

2

私は竜巻コードの周り掘って、このコードは()、その後io_loop.closeにスタックトレースを引き起こすTrueにall_fdsを設定していることがわかった:

def tearDown(self): 
    if (not IOLoop.initialized() or 
     self.io_loop is not IOLoop.instance()): 
     # Try to clean up any file descriptors left open in the ioloop. 
     # This avoids leaks, especially when tests are run repeatedly 
     # in the same process with autoreload (because curl does not 
     # set FD_CLOEXEC on its file descriptors) 
     self.io_loop.close(all_fds=True) 
    super(AsyncTestCase, self).tearDown() 

ので、解体をオーバーライド()でテストクラスはスタックトレースを停止します。

class AllServersHandlerTest(AsyncHTTPTestCase): 

    def tearDown(self): 
     pass 

    def get_app(self): 
     return Application([('/rest/test/', AllServersHandler)]) 

    def test_server_status_with_advertiser(self): 
     on_new_host(None, '127.0.0.1') 
     response = self.fetch('/rest/test/', method='GET') 
     result = json.loads(response.body, 'utf8').get('data') 
     self.assertEquals(['127.0.0.1'], result) 

このアプローチがどのような損害をもたらす可能性があるのか​​よくわからないので、他の人にもっと良い提案がある場合はお知らせください。

関連する問題