Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion ClickHouse.Driver.Tests/ADO/SessionConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,6 +35,7 @@ private static ClickHouseConnection CreateConnectionWithHttpClient(HttpClient ht
UseSession = useSession,
SessionId = sessionId,
HttpClient = httpClient,
CustomHeaders = TestUtilities.GetTestCustomHeaders(),
};
return new ClickHouseConnection(settings);
}
Expand Down Expand Up @@ -72,6 +76,7 @@ public async Task QueryWithTempTable_SessionIdSetInClickHouseClientSettings_Tabl
{
SessionId = sessionId,
UseSession = true,
CustomHeaders = TestUtilities.GetTestCustomHeaders(),
};

var connection = new ClickHouseConnection(settings);
Expand Down
5 changes: 4 additions & 1 deletion ClickHouse.Driver.Tests/Types/JsonModeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 27 additions & 1 deletion ClickHouse.Driver.Tests/Utilities/TestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ static TestUtilities()
/// </summary>
public const string TestDatabase = "test";

/// <summary>
/// The <c>X-ClickHouse-Replica-Tag</c> value that every test client sends to a Cloud service.
/// </summary>
/// <remarks>
/// 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 <c>Memory</c> table
/// keeps its rows on one replica, and a replica can read a <c>MergeTree</c> 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.
/// </remarks>
private static readonly string CloudReplicaTag = $"clickhouse-cs-tests-{Guid.NewGuid():N}";

/// <summary>
/// The HTTP headers that every test client sends: on Cloud the replica tag (see
/// <see cref="CloudReplicaTag"/>), else none. A test that makes its own
/// <see cref="ClickHouseClientSettings"/> for a real server must set them as its
/// <see cref="ClickHouseClientSettings.CustomHeaders"/>.
/// </summary>
public static IReadOnlyDictionary<string, string> GetTestCustomHeaders() =>
TestEnvironment == TestEnv.Cloud
? new Dictionary<string, string> { ["X-ClickHouse-Replica-Tag"] = CloudReplicaTag }
: new Dictionary<string, string>();

/// <summary>
/// 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 <see cref="CreateTableName"/>, not from
Expand Down Expand Up @@ -260,7 +285,8 @@ public static ClickHouseClientSettings GetTestClickHouseClientSettings(bool comp

return new ClickHouseClientSettings(builder)
{
UseFormDataParameters = useFormDataParameters
UseFormDataParameters = useFormDataParameters,
CustomHeaders = GetTestCustomHeaders(),
};
}

Expand Down
6 changes: 6 additions & 0 deletions ClickHouse.Driver/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading