Skip to content

Commit b3d766e

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
1 parent f2371fc commit b3d766e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

Lines changed: 10 additions & 4 deletions
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.
@@ -24,16 +24,22 @@ namespace Google.Cloud.Spanner.Data.CommonTesting
2424
/// </summary>
2525
public abstract class SpannerTableFixture : SpannerFixtureBase
2626
{
27+
private readonly object _lock = new object();
28+
2729
public string TableName { get; }
2830

2931
public SpannerTableFixture(string tableName)
3032
{
3133
TableName = tableName;
32-
if (Database.Fresh)
34+
lock(_lock)
3335
{
34-
Logger.DefaultLogger.Debug($"Creating table {TableName}");
35-
CreateTable();
36+
if (Database.Fresh)
37+
{
38+
Logger.DefaultLogger.Debug($"Creating table {TableName}");
39+
CreateTable();
40+
}
3641
}
42+
3743
RetryHelpers.ResetStats();
3844
Logger.DefaultLogger.Debug($"Populating table {TableName}");
3945
PopulateTable(Database.Fresh);

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

Lines changed: 4 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)