Merge pull request #48152 from vitlibar/make-test_disallow_concurrency-not-flaky

Make test test_disallow_concurrency less flaky
This commit is contained in:
Alexey Milovidov 2023-03-30 01:31:12 +03:00 committed by GitHub
commit fed6f50da6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,19 +125,29 @@ def test_concurrent_backups_on_same_node():
.query(f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name} ASYNC")
.split("\t")[0]
)
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE status == 'CREATING_BACKUP' AND id = '{id}'",
"CREATING_BACKUP",
status = (
nodes[0]
.query(f"SELECT status FROM system.backups WHERE id == '{id}'")
.rstrip("\n")
)
assert "Concurrent backups not supported" in nodes[0].query_and_get_error(
assert status in ["CREATING_BACKUP", "BACKUP_CREATED"]
error = nodes[0].query_and_get_error(
f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name}"
)
expected_errors = [
"Concurrent backups not supported",
f"Backup {backup_name} already exists",
]
assert any([expected_error in error for expected_error in expected_errors])
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE status == 'BACKUP_CREATED' AND id = '{id}'",
f"SELECT status FROM system.backups WHERE id = '{id}'",
"BACKUP_CREATED",
sleep_time=2,
retry_count=50,
)
# This restore part is added to confirm creating an internal backup & restore work
@ -161,18 +171,29 @@ def test_concurrent_backups_on_different_nodes():
.query(f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name} ASYNC")
.split("\t")[0]
)
assert_eq_with_retry(
nodes[1],
f"SELECT status FROM system.backups WHERE status == 'CREATING_BACKUP' AND id = '{id}'",
"CREATING_BACKUP",
status = (
nodes[1]
.query(f"SELECT status FROM system.backups WHERE id == '{id}'")
.rstrip("\n")
)
assert "Concurrent backups not supported" in nodes[0].query_and_get_error(
assert status in ["CREATING_BACKUP", "BACKUP_CREATED"]
error = nodes[0].query_and_get_error(
f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name}"
)
expected_errors = [
"Concurrent backups not supported",
f"Backup {backup_name} already exists",
]
assert any([expected_error in error for expected_error in expected_errors])
assert_eq_with_retry(
nodes[1],
f"SELECT status FROM system.backups WHERE status == 'BACKUP_CREATED' AND id = '{id}'",
f"SELECT status FROM system.backups WHERE id = '{id}'",
"BACKUP_CREATED",
sleep_time=2,
retry_count=50,
)
@ -181,22 +202,7 @@ def test_concurrent_restores_on_same_node():
backup_name = new_backup_name()
id = (
nodes[0]
.query(f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name} ASYNC")
.split("\t")[0]
)
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE status == 'CREATING_BACKUP' AND id = '{id}'",
"CREATING_BACKUP",
)
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE status == 'BACKUP_CREATED' AND id = '{id}'",
"BACKUP_CREATED",
)
nodes[0].query(f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name}")
nodes[0].query(
f"DROP TABLE tbl ON CLUSTER 'cluster' NO DELAY",
@ -218,22 +224,21 @@ def test_concurrent_restores_on_same_node():
)
assert status in ["RESTORING", "RESTORED"]
concurrent_error = nodes[0].query_and_get_error(
error = nodes[0].query_and_get_error(
f"RESTORE TABLE tbl ON CLUSTER 'cluster' FROM {backup_name}"
)
expected_errors = [
"Concurrent restores not supported",
"Cannot restore the table default.tbl because it already contains some data",
]
assert any(
[expected_error in concurrent_error for expected_error in expected_errors]
)
assert any([expected_error in error for expected_error in expected_errors])
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE id == '{restore_id}'",
"RESTORED",
sleep_time=2,
retry_count=50,
)
@ -242,22 +247,7 @@ def test_concurrent_restores_on_different_node():
backup_name = new_backup_name()
id = (
nodes[0]
.query(f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name} ASYNC")
.split("\t")[0]
)
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE status == 'CREATING_BACKUP' AND id = '{id}'",
"CREATING_BACKUP",
)
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE status == 'BACKUP_CREATED' AND id = '{id}'",
"BACKUP_CREATED",
)
nodes[0].query(f"BACKUP TABLE tbl ON CLUSTER 'cluster' TO {backup_name}")
nodes[0].query(
f"DROP TABLE tbl ON CLUSTER 'cluster' NO DELAY",
@ -279,20 +269,19 @@ def test_concurrent_restores_on_different_node():
)
assert status in ["RESTORING", "RESTORED"]
concurrent_error = nodes[1].query_and_get_error(
error = nodes[1].query_and_get_error(
f"RESTORE TABLE tbl ON CLUSTER 'cluster' FROM {backup_name}"
)
expected_errors = [
"Concurrent restores not supported",
"Cannot restore the table default.tbl because it already contains some data",
]
assert any(
[expected_error in concurrent_error for expected_error in expected_errors]
)
assert any([expected_error in error for expected_error in expected_errors])
assert_eq_with_retry(
nodes[0],
f"SELECT status FROM system.backups WHERE id == '{restore_id}'",
"RESTORED",
sleep_time=2,
retry_count=50,
)