diff --git a/.github/workflows/tests-macos.yml b/.github/workflows/tests-macos.yml
index 7a3f17143..a108f643d 100644
--- a/.github/workflows/tests-macos.yml
+++ b/.github/workflows/tests-macos.yml
@@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- os: [macos-14, macos-15-intel]
+ os: [macos-26, macos-15-intel]
steps:
- name: Checkout
uses: actions/checkout@v7
diff --git a/ClickHouse.Driver.Tests/ADO/SessionConnectionTest.cs b/ClickHouse.Driver.Tests/ADO/SessionConnectionTest.cs
index dac262514..96d451c46 100644
--- a/ClickHouse.Driver.Tests/ADO/SessionConnectionTest.cs
+++ b/ClickHouse.Driver.Tests/ADO/SessionConnectionTest.cs
@@ -21,7 +21,10 @@ private static DbConnection CreateConnection(bool useSession, string sessionId =
builder.Compression = true;
if (sessionId != null)
builder.SessionId = sessionId;
- return new ClickHouseConnection(builder.ToString());
+ return new ClickHouseConnection(new ClickHouseClientSettings(builder)
+ {
+ CustomHeaders = TestUtilities.GetTestCustomHeaders(),
+ });
}
private static ClickHouseConnection CreateConnectionWithHttpClient(HttpClient httpClient, bool useSession, string sessionId = null)
@@ -32,6 +35,7 @@ private static ClickHouseConnection CreateConnectionWithHttpClient(HttpClient ht
UseSession = useSession,
SessionId = sessionId,
HttpClient = httpClient,
+ CustomHeaders = TestUtilities.GetTestCustomHeaders(),
};
return new ClickHouseConnection(settings);
}
@@ -72,6 +76,7 @@ public async Task QueryWithTempTable_SessionIdSetInClickHouseClientSettings_Tabl
{
SessionId = sessionId,
UseSession = true,
+ CustomHeaders = TestUtilities.GetTestCustomHeaders(),
};
var connection = new ClickHouseConnection(settings);
diff --git a/ClickHouse.Driver.Tests/Types/JsonModeTests.cs b/ClickHouse.Driver.Tests/Types/JsonModeTests.cs
index 7e6a6634c..fe85d0b2c 100644
--- a/ClickHouse.Driver.Tests/Types/JsonModeTests.cs
+++ b/ClickHouse.Driver.Tests/Types/JsonModeTests.cs
@@ -63,7 +63,10 @@ private ClickHouseClientSettings GetSettingsWithJsonMode(JsonReadMode readMode =
builder.JsonReadMode = readMode;
builder.JsonWriteMode = writeMode;
- var settings = new ClickHouseClientSettings(builder);
+ var settings = new ClickHouseClientSettings(builder)
+ {
+ CustomHeaders = TestUtilities.GetTestCustomHeaders(),
+ };
// Add experimental JSON type support
settings.CustomSettings["allow_experimental_json_type"] = 1;
diff --git a/ClickHouse.Driver.Tests/Utilities/TestUtilities.cs b/ClickHouse.Driver.Tests/Utilities/TestUtilities.cs
index c8c25fb03..5b8233679 100644
--- a/ClickHouse.Driver.Tests/Utilities/TestUtilities.cs
+++ b/ClickHouse.Driver.Tests/Utilities/TestUtilities.cs
@@ -90,6 +90,31 @@ static TestUtilities()
///
public const string TestDatabase = "test";
+ ///
+ /// The X-ClickHouse-Replica-Tag value that every test client sends to a Cloud service.
+ ///
+ ///
+ /// The Cloud proxy can send each HTTP request to a different replica, also on one keep-alive
+ /// connection. A temporary table exists only in its session on one replica, a Memory table
+ /// keeps its rows on one replica, and a replica can read a MergeTree table before it has the
+ /// parts that another replica inserted. With replica-aware routing, the proxy sends all requests
+ /// with the same tag to the same replica while the number of replicas stays the same, so one tag
+ /// for the whole run keeps these tests on one replica. See
+ /// https://clickhouse.com/docs/products/cloud/features/infrastructure/replica-aware-routing.
+ ///
+ private static readonly string CloudReplicaTag = $"clickhouse-cs-tests-{Guid.NewGuid():N}";
+
+ ///
+ /// The HTTP headers that every test client sends: on Cloud the replica tag (see
+ /// ), else none. A test that makes its own
+ /// for a real server must set them as its
+ /// .
+ ///
+ public static IReadOnlyDictionary GetTestCustomHeaders() =>
+ TestEnvironment == TestEnv.Cloud
+ ? new Dictionary { ["X-ClickHouse-Replica-Tag"] = CloudReplicaTag }
+ : new Dictionary();
+
///
/// Identifies which of the concurrently running net6.0/net8.0/net9.0/net10.0 suites produced a
/// name. Uniqueness itself comes from the random token in , not from
@@ -260,7 +285,8 @@ public static ClickHouseClientSettings GetTestClickHouseClientSettings(bool comp
return new ClickHouseClientSettings(builder)
{
- UseFormDataParameters = useFormDataParameters
+ UseFormDataParameters = useFormDataParameters,
+ CustomHeaders = GetTestCustomHeaders(),
};
}
diff --git a/ClickHouse.Driver/AGENTS.md b/ClickHouse.Driver/AGENTS.md
index 5ab86d481..7b16f381e 100644
--- a/ClickHouse.Driver/AGENTS.md
+++ b/ClickHouse.Driver/AGENTS.md
@@ -213,6 +213,12 @@ var table = TestUtilities.CreateTableName(); // + DROP TABLE IF EXISTS in you
serialisation suites.
- **Test utilities**: before writing tests, read `Utilities/TestUtilities.cs` to understand existing
config and utility patterns, including `CreateTableName`/`SanitizeTableName`.
+- **Clients for a real server**: get them from `TestUtilities.GetTestClickHouseClient()` /
+ `GetTestClickHouseConnection()` or `AbstractConnectionTestFixture`. A test that makes its own
+ `ClickHouseClientSettings` must set `CustomHeaders = TestUtilities.GetTestCustomHeaders()`. On
+ Cloud, these headers keep every request of the run on one replica; without them, a session, a
+ `Memory` table or a read of a row that the test just inserted can reach another replica and fail.
+ A connection string cannot carry the headers, so use the settings constructor.
- **`system.query_log`**: `QueryLog.ScalarAsync` fails with a distinct message when no row appears;
`QueryLog.CountAsync` waits for `minimumCount` rows before reporting.
- **Server version gating**: `[FromVersion]`, `[IgnoreInVersion]` and `[RequiredFeature]` in