mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-30 19:46:48 +00:00
50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
#
|
|
# Copyright (C) 2024-present ScyllaDB
|
|
#
|
|
# SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.1
|
|
#
|
|
|
|
import asyncio
|
|
import time
|
|
from test.pylib.rest_client import inject_error
|
|
from test.pylib.util import wait_for_cql_and_get_hosts
|
|
import pytest
|
|
from cassandra.protocol import WriteTimeout
|
|
from test.cluster.util import new_test_keyspace
|
|
|
|
|
|
@pytest.mark.skip_mode(mode='debug', reason='aarch64/debug is unpredictably slow', platform_key='aarch64')
|
|
async def test_cas_semaphore(manager):
|
|
""" This is a regression test for scylladb/scylladb#19698 """
|
|
servers = await manager.servers_add(1, cmdline=['--smp', '1'])
|
|
|
|
host = await wait_for_cql_and_get_hosts(manager.cql, {servers[0]}, time.time() + 60)
|
|
|
|
async with new_test_keyspace(manager, "WITH REPLICATION = {'class': 'NetworkTopologyStrategy', 'replication_factor': 1}") as ks:
|
|
table = f"{ks}.test"
|
|
await manager.cql.run_async(f"CREATE TABLE {table} (a int PRIMARY KEY, b int)")
|
|
|
|
# Lower write timeout only for the CAS phase, after paxos state table
|
|
# creation (which goes through raft) has had time to complete with the
|
|
# default timeout.
|
|
await manager.server_update_config(servers[0].server_id, 'write_request_timeout_in_ms', 500)
|
|
|
|
async with inject_error(manager.api, servers[0].ip_addr, 'cas_timeout_after_lock'):
|
|
res = [manager.cql.run_async(f"INSERT INTO {table} (a) VALUES (0) IF NOT EXISTS", host=host[0]) for r in range(10)]
|
|
try:
|
|
await asyncio.gather(*res)
|
|
except WriteTimeout:
|
|
pass
|
|
|
|
# Restore a generous timeout so the second batch isn't affected by
|
|
# lingering raft apply latency.
|
|
await manager.server_update_config(servers[0].server_id, 'write_request_timeout_in_ms', 10000)
|
|
|
|
res = [manager.cql.run_async(f"INSERT INTO {table} (a) VALUES (0) IF NOT EXISTS", host=host[0]) for r in range(10)]
|
|
await asyncio.gather(*res)
|
|
|
|
metrics = await manager.metrics.query(servers[0].ip_addr)
|
|
contention = metrics.get(name="scylla_storage_proxy_coordinator_cas_write_contention_count")
|
|
|
|
assert contention == None
|