Skip to content

Commit caef94e

Browse files
committed
chore: Add extra condition for emulator tests with concurrent txn
chore: Add extra condition for emulator tests with concurrent txn in ManagedSession chore: add a lock on test fixture table creation chore: Emulator changes
1 parent f2371fc commit caef94e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

apis/Google.Cloud.Spanner.Data/Google.Cloud.Spanner.Data.CommonTesting/SpannerTableFixture.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -29,11 +29,13 @@ public abstract class SpannerTableFixture : SpannerFixtureBase
2929
public SpannerTableFixture(string tableName)
3030
{
3131
TableName = tableName;
32+
3233
if (Database.Fresh)
3334
{
3435
Logger.DefaultLogger.Debug($"Creating table {TableName}");
3536
CreateTable();
3637
}
38+
3739
RetryHelpers.ResetStats();
3840
Logger.DefaultLogger.Debug($"Populating table {TableName}");
3941
PopulateTable(Database.Fresh);

apis/Google.Cloud.Spanner.V1/Google.Cloud.Spanner.V1/ManagedSession.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ internal bool SessionHasExpired(double intervalInDays = SoftRefreshIntervalInDay
154154
{
155155
DateTime currentTime = _clock.GetCurrentDateTimeUtc();
156156
DateTime? sessionCreateTime = _session?.CreateTime.ToDateTime(); // Inherent conversion into UTC DateTime
157-
if (_session == null || _session.Expired || currentTime - sessionCreateTime >= TimeSpan.FromDays(intervalInDays))
157+
if (_session == null
158+
|| _session.Expired
159+
|| !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SPANNER_EMULATOR_HOST"))
160+
|| currentTime - sessionCreateTime >= TimeSpan.FromDays(intervalInDays))
158161
{
159162
return true;
160163
}
@@ -189,7 +192,7 @@ private async Task CreateOrRefreshSessionsAsync(CancellationToken cancellationTo
189192

190193
// Hard refresh or initial session creation,
191194
// wrap this in a Task since the _sessionCreationTask task could also be null if refresh completes/fails.
192-
Task currentCreationTask = Task.Run(() => TriggerRefresh(HardRefreshIntervalInDays));
195+
Task currentCreationTask = TriggerRefresh(HardRefreshIntervalInDays);
193196

194197
// 2b. Block the current caller on the task (Hard Refresh requirement)
195198
// If we initiated the task, we are waiting for our own task.

0 commit comments

Comments
 (0)