|
| 1 | +# |
| 2 | +# Based on Aphyr's test for CockroachDB. |
| 3 | +# |
| 4 | + |
| 5 | +import unittest |
| 6 | +import time |
| 7 | +import subprocess |
| 8 | +import datetime |
| 9 | +import docker |
| 10 | +import warnings |
| 11 | + |
| 12 | +from lib.bank_client import MtmClient |
| 13 | +from lib.failure_injector import * |
| 14 | +from lib.test_helper import * |
| 15 | + |
| 16 | + |
| 17 | +class MajorTest(unittest.TestCase, TestHelper): |
| 18 | + |
| 19 | + @classmethod |
| 20 | + def setUpClass(cls): |
| 21 | + subprocess.check_call(['docker-compose', |
| 22 | + '-f', 'support/two_nodes.yml', |
| 23 | + 'up', |
| 24 | + '--force-recreate', |
| 25 | + '--build', |
| 26 | + '-d']) |
| 27 | + |
| 28 | + # XXX: add normal wait here |
| 29 | + time.sleep(TEST_SETUP_TIME) |
| 30 | + |
| 31 | + cls.client = MtmClient([ |
| 32 | + "dbname=regression user=postgres host=127.0.0.1 port=15432", |
| 33 | + "dbname=regression user=postgres host=127.0.0.1 port=15433" |
| 34 | + ], n_accounts=1000) |
| 35 | + cls.client.bgrun() |
| 36 | + |
| 37 | + @classmethod |
| 38 | + def tearDownClass(cls): |
| 39 | + print('tearDown') |
| 40 | + cls.client.stop() |
| 41 | + |
| 42 | + time.sleep(TEST_STOP_DELAY) |
| 43 | + |
| 44 | + if not cls.client.is_data_identic(): |
| 45 | + raise AssertionError('Different data on nodes') |
| 46 | + |
| 47 | + if cls.client.no_prepared_tx() != 0: |
| 48 | + raise AssertionError('There are some uncommitted tx') |
| 49 | + |
| 50 | + # XXX: check nodes data identity here |
| 51 | + # subprocess.check_call(['docker-compose','down']) |
| 52 | + |
| 53 | + def setUp(self): |
| 54 | + warnings.simplefilter("ignore", ResourceWarning) |
| 55 | + time.sleep(20) |
| 56 | + print('Start new test at ',datetime.datetime.utcnow()) |
| 57 | + |
| 58 | + def tearDown(self): |
| 59 | + print('Finish test at ',datetime.datetime.utcnow()) |
| 60 | + |
| 61 | + def test_node_partition(self): |
| 62 | + print('### test_node_partition ###') |
| 63 | + |
| 64 | + aggs_failure, aggs = self.performFailure(SingleNodePartition('node2')) |
| 65 | + |
| 66 | + self.assertNoCommits(aggs_failure) |
| 67 | + self.assertIsolation(aggs_failure) |
| 68 | + |
| 69 | + self.assertCommits(aggs) |
| 70 | + self.assertIsolation(aggs) |
| 71 | + |
| 72 | +if __name__ == '__main__': |
| 73 | + unittest.main() |
| 74 | + |
0 commit comments