diff --git a/asynctnt/instance.py b/asynctnt/instance.py index feb5c85..c764e75 100644 --- a/asynctnt/instance.py +++ b/asynctnt/instance.py @@ -194,6 +194,7 @@ def get_random_port(): def _create_initlua_template(self): return """ + box.cfg{ listen = "${host}:${port}", wal_mode = "${wal_mode}", @@ -385,7 +386,7 @@ def start(self): attempts = math.ceil(self._timeout / interval) while attempts > 0: try: - status = self.command('box.info.status', print_greeting=False) + status = self.command('box.info.status', print_greeting=True) if status: status = status[0] if status == 'running': diff --git a/tests/files/app.lua b/tests/files/app.lua index ba0d955..2cdd5db 100644 --- a/tests/files/app.lua +++ b/tests/files/app.lua @@ -24,6 +24,19 @@ end _G.B = bootstrap() +function change_format() + box.space.tester:format({ + {type=B.types.unsigned, name='f1'}, + {type=B.types.string, name='f2'}, + {type=B.types.unsigned, name='f3'}, + {type=B.types.unsigned, name='f4'}, + {type=B.types.any, name='f5'}, + {type=B.types.any, name='f6'}, + }) +end + +box.schema.func.create('change_format', {setuid=true}) + box.once('v1', function() box.schema.user.create('t1', {password = 't1'}) @@ -31,7 +44,7 @@ box.once('v1', function() local s = box.schema.create_space('tester') s:format({ - {type=B.types.string, name='f1'}, + {type=B.types.unsigned, name='f1'}, {type=B.types.string, name='f2'}, {type=B.types.unsigned, name='f3'}, {type=B.types.unsigned, name='f4'}, diff --git a/tests/test_common.py b/tests/test_common.py index c37bef7..ac24b52 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -12,8 +12,8 @@ class CommonTestCase(BaseTarantoolTestCase): async def test__encoding_utf8(self): p, p_cmp = get_complex_param(replace_bin=False) - data = [1, 'hello', p] - data_cmp = [1, 'hello', p_cmp] + data = [1, 'hello', 1, 0, p] + data_cmp = [1, 'hello', 1, 0, p_cmp] res = await self.conn.insert(self.TESTER_SPACE_ID, data) self.assertListEqual(res.body, [data_cmp], 'Body ok') @@ -25,8 +25,8 @@ async def test__encoding_cp1251(self): await self.tnt_reconnect(encoding='cp1251') p, p_cmp = get_complex_param(replace_bin=False) - data = [1, 'hello', p] - data_cmp = [1, 'hello', p_cmp] + data = [1, 'hello', 1, 0, p] + data_cmp = [1, 'hello', 1, 0, p_cmp] res = await self.conn.insert(self.TESTER_SPACE_ID, data) self.assertListEqual(res.body, [data_cmp], 'Body ok') @@ -55,6 +55,23 @@ async def test__schema_refetch_on_schema_change(self): self.assertGreater(self.conn.schema_id, schema_before, 'Schema changed') + async def test__schema_refetch_on_schema_change_format(self): + await self.tnt_reconnect(auto_refetch_schema=True, username='t1', password='t1') + self.assertTrue(self.conn.fetch_schema) + self.assertTrue(self.conn.auto_refetch_schema) + schema_before = self.conn.schema_id + self.assertNotEqual(schema_before, -1) + + await self.conn.call('change_format') + + try: + await self.conn.ping() + except Exception as e: + self.fail(e) + + self.assertGreater(self.conn.schema_id, schema_before, + 'Schema changed') + async def test__schema_no_fetch_and_refetch(self): await self.tnt_reconnect(auto_refetch_schema=False, fetch_schema=False) diff --git a/tests/test_op_delete.py b/tests/test_op_delete.py index f79bde5..29b6dd5 100644 --- a/tests/test_op_delete.py +++ b/tests/test_op_delete.py @@ -10,8 +10,8 @@ class DeleteTestCase(BaseTarantoolTestCase): async def _fill_data(self): data = [ - [0, 'a', 1], - [1, 'b', 0], + [0, 'a', 1, 2, 'hello my darling'], + [1, 'b', 3, 4, 'hello my darling, again'], ] for t in data: await self.conn.insert(self.TESTER_SPACE_ID, t) @@ -132,7 +132,7 @@ async def test__delete_dict_key(self): self.assertListEqual(res.body, [data[0]], 'Body ok') async def test__delete_dict_resp(self): - data = [0, 'hello', 0, 'wow'] + data = [0, 'hello', 0, 1, 'wow'] await self.conn.insert(self.TESTER_SPACE_ID, data) res = await self.conn.delete(self.TESTER_SPACE_ID, [0], @@ -141,5 +141,6 @@ async def test__delete_dict_resp(self): 'f1': 0, 'f2': 'hello', 'f3': 0, - 'f4': 'wow' + 'f4': 1, + 'f5': 'wow' }]) diff --git a/tests/test_op_insert.py b/tests/test_op_insert.py index db8d97a..740908c 100644 --- a/tests/test_op_insert.py +++ b/tests/test_op_insert.py @@ -9,7 +9,7 @@ class InsertTestCase(BaseTarantoolTestCase): async def test__insert_one(self): - data = [1, 'hello'] + data = [1, 'hello', 1, 4, 'what is up'] res = await self.conn.insert(self.TESTER_SPACE_ID, data) self.assertIsInstance(res, Response, 'Got response') @@ -18,7 +18,7 @@ async def test__insert_one(self): self.assertListEqual(res.body, [data], 'Body ok') async def test__insert_by_name(self): - data = [1, 'hello'] + data = [1, 'hello', 1, 4, 'what is up'] res = await self.conn.insert(self.TESTER_SPACE_NAME, data) self.assertIsInstance(res, Response, 'Got response') @@ -29,28 +29,30 @@ async def test__insert_by_name(self): async def test__insert_by_name_no_schema(self): await self.tnt_reconnect(fetch_schema=False) - data = [1, 'hello'] + data = [1, 'hello', 1, 4, 'what is up'] with self.assertRaises(TarantoolSchemaError): await self.conn.insert(self.TESTER_SPACE_NAME, data) async def test__insert_complex_tuple(self): p, p_cmp = get_complex_param(replace_bin=False) - data = [1, 'hello', p] - data_cmp = [1, 'hello', p_cmp] + data = [1, 'hello', 1, 2, p] + data_cmp = [1, 'hello', 1, 2, p_cmp] res = await self.conn.insert(self.TESTER_SPACE_ID, data) self.assertListEqual(res.body, [data_cmp], 'Body ok') async def test__insert_replace(self): - data = [1, 'hello'] + data = [1, 'hello', 1, 4, 'what is up'] await self.conn.insert(self.TESTER_SPACE_ID, data) try: - res = await self.conn.insert(self.TESTER_SPACE_ID, [1, 'hello2'], + data = [1, 'hello2', 1, 4, 'what is up'] + res = await self.conn.insert(self.TESTER_SPACE_ID, + t=data, replace=True) - self.assertListEqual(res.body, [[1, 'hello2']], 'Body ok') + self.assertListEqual(res.body, [data], 'Body ok') except Exception as e: self.fail(e) @@ -65,11 +67,11 @@ async def test__insert_invalid_types(self): await self.conn.insert(self.TESTER_SPACE_ID) async def test__replace(self): - data = [1, 'hello'] + data = [1, 'hello', 1, 4, 'what is up'] res = await self.conn.replace(self.TESTER_SPACE_ID, data) self.assertListEqual(res.body, [data], 'Body ok') - data = [1, 'hello2'] + data = [1, 'hello2', 1, 5, 'what is up'] res = await self.conn.replace(self.TESTER_SPACE_ID, data) self.assertListEqual(res.body, [data], 'Body ok') @@ -86,9 +88,12 @@ async def test__replace_invalid_types(self): async def test__insert_dict_key(self): data = { 'f1': 1, - 'f2': 'hello' + 'f2': 'hello', + 'f3': 5, + 'f4': 6, + 'f5': 'hello dog', } - data_cmp = [1, 'hello', None, None, None] + data_cmp = [1, 'hello', 5, 6, 'hello dog'] res = await self.conn.insert(self.TESTER_SPACE_ID, data) self.assertListEqual(res.body, [data_cmp], 'Body ok') @@ -96,32 +101,35 @@ async def test__insert_dict_key_holes(self): data = { 'f1': 1, 'f2': 'hello', - 'f4': 'wow' + 'f3': 3, + 'f4': 6, + 'f5': None, } - data_cmp = [1, 'hello', None, 'wow', None] + data_cmp = [1, 'hello', 3, 6, None] res = await self.conn.insert(self.TESTER_SPACE_ID, data) self.assertListEqual(res.body, [data_cmp], 'Body ok') async def test__insert_dict_resp(self): - data = [0, 'hello', 0, 'wow'] + data = [0, 'hello', 0, 5, 'wow'] res = await self.conn.insert(self.TESTER_SPACE_ID, data, tuple_as_dict=True) self.assertListEqual(res.body, [{ 'f1': 0, 'f2': 'hello', 'f3': 0, - 'f4': 'wow' + 'f4': 5, + 'f5': 'wow' }]) async def test__insert_dict_resp_extra(self): - data = [0, 'hello', 5, 'wow', 'help', 'common', 'yo'] + data = [0, 'hello', 5, 6, 'help', 'common', 'yo'] res = await self.conn.insert(self.TESTER_SPACE_ID, data, tuple_as_dict=True) self.assertListEqual(res.body, [{ 'f1': 0, 'f2': 'hello', 'f3': 5, - 'f4': 'wow', + 'f4': 6, 'f5': 'help', '': ['common', 'yo'] }]) diff --git a/tests/test_op_select.py b/tests/test_op_select.py index d2b171e..4c7ee31 100644 --- a/tests/test_op_select.py +++ b/tests/test_op_select.py @@ -14,7 +14,7 @@ class SelectTestCase(BaseTarantoolTestCase): async def _fill_data(self, count=3): data = [] for i in range(count): - t = [i, str(i)] + t = [i, str(i), 1, 2, 'something'] data.append(t) await self.conn.insert(self.TESTER_SPACE_ID, t) return data @@ -24,7 +24,10 @@ async def _fill_data_dict(self, count=3): for i in range(count): t = { 'f1': i, - 'f2': str(i) + 'f2': str(i), + 'f3': 1, + 'f4': 2, + 'f5': 'something', } t = await self.conn.insert(self.TESTER_SPACE_ID, t, tuple_as_dict=True) @@ -125,8 +128,9 @@ async def test__select_by_key_multiple_items_index(self): data = await self._fill_data() next_id = data[-1][0] + 1 next_txt = data[-1][1] - await self.conn.insert(self.TESTER_SPACE_ID, [next_id, next_txt]) - data.append([next_id, next_txt]) + await self.conn.insert(self.TESTER_SPACE_ID, + [next_id, next_txt, 1, 2, 'text']) + data.append([next_id, next_txt, 1, 2, 'text']) res = await self.conn.select(self.TESTER_SPACE_NAME, [next_txt], index='txt') @@ -172,7 +176,7 @@ async def test__select_iterator_str(self): async def test__select_complex(self): p, p_cmp = get_complex_param(replace_bin=False) - data = [1, 'hello', p_cmp] + data = [1, 'hello2', 1, 4, p_cmp] await self.conn.insert(self.TESTER_SPACE_ID, data) diff --git a/tests/test_op_update.py b/tests/test_op_update.py index 095c22f..02f5337 100644 --- a/tests/test_op_update.py +++ b/tests/test_op_update.py @@ -15,8 +15,9 @@ class UpdateTestCase(BaseTarantoolTestCase): async def _fill_data(self): data = [ - [0, 'a', 1, 5], - [1, 'b', 0, 6], + [0, 'a', 1, 5, 'data1'], + [1, 'b', 8, 6, 'data2'], + [2, 'c', 10, 12, 'data3', 'extra_field'], ] for t in data: await self.conn.insert(self.TESTER_SPACE_ID, t) @@ -47,9 +48,9 @@ async def test__update_one_delete(self): data = await self._fill_data() res = await self.conn.update(self.TESTER_SPACE_ID, - [1], [['#', 2, 1]]) - data[1].pop(2) - self.assertListEqual(res.body, [data[1]], 'Body ok') + [2], [['#', 5, 1]]) + data[2].pop(5) + self.assertListEqual(res.body, [data[2]], 'Body ok') async def test__update_one_plus(self): data = await self._fill_data() @@ -88,9 +89,9 @@ async def test__update_one_minus(self): data = await self._fill_data() res = await self.conn.update(self.TESTER_SPACE_ID, - [1], [['-', 2, 3]]) - data[1][2] -= 3 - self.assertListEqual(res.body, [data[1]], 'Body ok') + [0], [['-', 2, 1]]) + data[0][2] -= 1 + self.assertListEqual(res.body, [data[0]], 'Body ok') async def test__update_one_minus_negative(self): data = await self._fill_data() @@ -170,27 +171,27 @@ async def test__update_one_bxor(self): self.assertListEqual(res.body, [data[1]], 'Body ok') async def test__update_splice(self): - data = [1, 'hello', 'hi'] + data = [1, 'hello2', 1, 4, 'what is up'] await self.conn.insert(self.TESTER_SPACE_ID, data) res = await self.conn.update(self.TESTER_SPACE_ID, - [1], [[':', 2, 1, 3, '!!!']]) + [1], [[':', 1, 1, 3, '!!!']]) - data[2] = 'h!!!' + data[1] = 'h!!!o2' self.assertListEqual(res.body, [data], 'Body ok') async def test__update_splice_bytes(self): - data = [1, 'hello', 'hi'] + data = [1, 'hello2', 1, 4, 'what is up'] await self.conn.insert(self.TESTER_SPACE_ID, data) res = await self.conn.update(self.TESTER_SPACE_ID, - [1], [[b':', 2, 1, 3, '!!!']]) + [1], [[b':', 1, 1, 3, '!!!']]) - data[2] = 'h!!!' + data[1] = 'h!!!o2' self.assertListEqual(res.body, [data], 'Body ok') async def test__update_splice_wrong_args(self): - data = [1, 'hello', 'hi'] + data = [1, 'hello2', 1, 4, 'what is up'] await self.conn.insert(self.TESTER_SPACE_ID, data) with self.assertRaisesRegex( @@ -246,23 +247,23 @@ async def test__update_splice_wrong_args(self): [1], [('+', 2, {})]) async def test__update_multiple_operations(self): - t = [1, '1', 1, 0, 3, 4, 8, 'hello'] + t = [1, '1', 1, 5, 'hello', 3, 4, 8] await self.conn.insert(self.TESTER_SPACE_ID, t) t[2] += 1 t[3] -= 4 - t[4] &= 5 - t[5] |= 7 - t[6] = 100 - t[7] = 'h!!!o' + t[5] &= 5 + t[6] |= 7 + t[7] = 100 + t[4] = 'h!!!o' operations = [ ['+', 2, 1], ['-', 3, 4], - ['&', 4, 5], - ['|', 5, 7], - ['=', 6, 100], - [':', 7, 1, 3, '!!!'], + ['&', 5, 5], + ['|', 6, 7], + ['=', 7, 100], + [':', 4, 1, 3, '!!!'], ] res = await self.conn.update(self.TESTER_SPACE_ID, @@ -390,5 +391,6 @@ async def test__update_dict_resp(self): 'f1': data[0][0], 'f2': data[0][1], 'f3': data[0][2], - 'f4': data[0][3] + 'f4': data[0][3], + 'f5': data[0][4], }]) diff --git a/tests/test_op_upsert.py b/tests/test_op_upsert.py index 988caaa..33c4210 100644 --- a/tests/test_op_upsert.py +++ b/tests/test_op_upsert.py @@ -19,7 +19,7 @@ async def _fill_data(self): return data async def test__upsert_empty_one_assign(self): - data = [0, 'hello', 1] + data = [0, 'hello2', 1, 4, 'what is up'] res = await self.conn.upsert(self.TESTER_SPACE_ID, data, [['=', 2, 2]]) @@ -32,7 +32,7 @@ async def test__upsert_empty_one_assign(self): self.assertListEqual(res.body, [data], 'Body ok') async def test__upsert_update_one_assign(self): - data = [0, 'hello', 1] + data = [0, 'hello2', 1, 4, 'what is up'] await self.conn.insert(self.TESTER_SPACE_ID, data) res = await self.conn.upsert(self.TESTER_SPACE_ID, @@ -47,7 +47,7 @@ async def test__upsert_update_one_assign(self): self.assertListEqual(res.body, [data], 'Body ok') async def test__upsert_by_name(self): - data = [0, 'hello', 1] + data = [0, 'hello2', 1, 4, 'what is up'] await self.conn.upsert(self.TESTER_SPACE_NAME, data, [['=', 2, 2]]) @@ -68,8 +68,10 @@ async def test__upsert_by_name_no_schema(self): async def test__upsert_dict_key(self): data = { 'f1': 0, + 'f2': 'hello', 'f3': 1, - 'f2': 'hello' + 'f4': 2, + 'f5': 100, } res = await self.conn.upsert(self.TESTER_SPACE_ID, @@ -78,14 +80,16 @@ async def test__upsert_dict_key(self): res = await self.conn.select(self.TESTER_SPACE_ID, [0]) self.assertListEqual(res.body, - [[0, 'hello', 1, None, None]], + [[0, 'hello', 1, 2, 100]], 'Body ok') async def test__update_dict_resp_no_effect(self): data = { 'f1': 0, + 'f2': 'hello', 'f3': 1, - 'f2': 'hello' + 'f4': 10, + 'f5': 1000, } res = await self.conn.upsert(self.TESTER_SPACE_ID,