Skip to content

Commit a88dc20

Browse files
committed
test: Adding some logging for emulator testing
test: Adding some logging for emulator testing test: Special conditioning for emulator test: Changes to support some tests on the emulator chore: adding some logging for emulator chore: try create new mux for emulator to see if tests get fixed
1 parent ab528a1 commit a88dc20

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,10 @@ public SpannerConnection GetConnection(Logger logger, bool logCommitStats = fals
185185

186186
public async Task<ManagedSession> GetManagedSession()
187187
{
188-
if (_multiplexSession != null)
188+
if (_multiplexSession != null && GetEnvironmentVariableOrDefault("SPANNER_EMULATOR_HOST", null) == null)
189189
{
190+
// Only return the same multiplex session if we are NOT testing on the emulator
191+
// The emulator does not handle concurrent transactions on a single multiplex session well
190192
return _multiplexSession;
191193
}
192194

apis/Google.Cloud.Spanner.Data/Google.Cloud.Spanner.Data.IntegrationTests/WriteTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,16 @@ public async Task BadColumnName()
320320
cmd.Parameters.Add("badjuju", SpannerDbType.String, IdGenerator.FromGuid());
321321
var e = await Assert.ThrowsAsync<SpannerException>(() => cmd.ExecuteNonQueryAsyncWithRetry());
322322
Logger.DefaultLogger.Debug($"BadColumnName: Caught error code: {e.ErrorCode}");
323-
Assert.Equal(ErrorCode.NotFound, e.ErrorCode);
323+
if (_fixture.RunningOnEmulator)
324+
{
325+
// Emulator vs Prod give different exceptions for this case with Multiplex Sessions
326+
Assert.Equal(ErrorCode.InvalidArgument, e.ErrorCode);
327+
}
328+
else
329+
{
330+
Assert.Equal(ErrorCode.NotFound, e.ErrorCode);
331+
}
332+
324333
Assert.False(e.IsTransientSpannerFault());
325334
}
326335
}
@@ -348,7 +357,17 @@ public async Task BadTableName()
348357
cmd.Parameters.Add("K", SpannerDbType.String, IdGenerator.FromGuid());
349358
var e = await Assert.ThrowsAsync<SpannerException>(() => cmd.ExecuteNonQueryAsyncWithRetry());
350359
Logger.DefaultLogger.Debug($"BadTableName: Caught error code: {e.ErrorCode}");
351-
Assert.Equal(ErrorCode.NotFound, e.ErrorCode);
360+
361+
if(_fixture.RunningOnEmulator)
362+
{
363+
// Emulator vs Prod give different exceptions for this case with Multiplex Sessions
364+
Assert.Equal(ErrorCode.InvalidArgument, e.ErrorCode);
365+
}
366+
else
367+
{
368+
Assert.Equal(ErrorCode.NotFound, e.ErrorCode);
369+
}
370+
352371
Assert.False(e.IsTransientSpannerFault());
353372
}
354373
}

apis/Google.Cloud.Spanner.Data/Google.Cloud.Spanner.Data/SessionPoolManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static SessionPoolManager()
4949
/// is specified on construction.
5050
/// </summary>
5151
public static SessionPoolManager Default { get; } =
52-
new SessionPoolManager(new SessionPoolOptions(), CreateDefaultSpannerSettings(), Logger.DefaultLogger, CreateClientAsync);
52+
new SessionPoolManager(new ManagedSessionOptions(), CreateDefaultSpannerSettings(), Logger.DefaultLogger, CreateClientAsync);
5353

5454
private readonly Func<SpannerClientCreationOptions, SpannerSettings, Task<SpannerClient>> _clientFactory;
5555

@@ -161,6 +161,12 @@ internal Task<ManagedSession> AcquireManagedSessionAsync(SpannerClientCreationOp
161161
{
162162
SessionPoolSegmentKey segmentKey = SessionPoolSegmentKey.Create(dbName).WithDatabaseRole(dbRole);
163163
GaxPreconditions.CheckNotNull(options, nameof(options));
164+
Logger.Warn($"Checking existance of mux in dictionary {segmentKey}, {_targetedMuxSessions.ContainsKey((options, segmentKey))}");
165+
if(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SPANNER_EMULATOR_HOST")) && _targetedMuxSessions.ContainsKey((options, segmentKey)))
166+
{
167+
_targetedMuxSessions[(options, segmentKey)] = CreateMultiplexSessionAsync();
168+
}
169+
164170
var muxSession = _targetedMuxSessions.GetOrAdd((options, segmentKey), CreateMultiplexSessionAsync());
165171
return muxSession;
166172

0 commit comments

Comments
 (0)