diff --git a/neo/client/app.py b/neo/client/app.py index 42b87c62081b22485115fde55c74ddbe9b57a291..dff88dd419c6fc0c07aa1c4e2a49ac83aa2aec4b 100644 --- a/neo/client/app.py +++ b/neo/client/app.py @@ -50,9 +50,8 @@ from neo.util import u64, parseMasterList class ThreadContext(object): - _threads_dict = {} - def __init__(self): + super(ThreadContext, self).__setattr__('_threads_dict', {}) self.txn_info = 0 self.history = None self.node_tids = {} diff --git a/neo/tests/client/testClientApp.py b/neo/tests/client/testClientApp.py index 0092e9694e9e8acf6ff7c5c5626bcd9a873ae16f..7e212630085d0e753a48b6cadec6c9c700cc353d 100644 --- a/neo/tests/client/testClientApp.py +++ b/neo/tests/client/testClientApp.py @@ -939,6 +939,19 @@ class ClientApplicationTests(NeoTestBase): # check disabled since we reonnect to pmn #self.assertRaises(NEOStorageError, app._askPrimary, packet) + def test_threadContextIsolation(self): + """ Thread context properties must not be visible accross instances + while remaining in the same thread """ + app1 = self.getApp() + app1_local = app1.local_var + app2 = self.getApp() + app2_local = app2.local_var + property_id = 'thread_context_test' + self.assertFalse(hasattr(app1_local, property_id)) + self.assertFalse(hasattr(app2_local, property_id)) + setattr(app1_local, property_id, 'value') + self.assertTrue(hasattr(app1_local, property_id)) + self.assertFalse(hasattr(app2_local, property_id)) if __name__ == '__main__': unittest.main()