Skip to content

Commit 277f78d

Browse files
authored
chore: support setting an execution time for Commit in .NET mock server (#568)
Adding an ExecutionTime (for example an error) had no effect for the Commit method in the .NET mock server.
1 parent 11e1d88 commit 277f78d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-mockserver/MockSpannerServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ public override Task<CommitResponse> Commit(CommitRequest request, ServerCallCon
420420
_contexts.Enqueue(context);
421421
_headers.Enqueue(context.RequestHeaders);
422422
TryFindSession(request.SessionAsSessionName);
423+
_executionTimes.TryGetValue(nameof(Commit), out var executionTime);
424+
executionTime?.SimulateExecutionTime();
423425
if (request.TransactionCase == CommitRequest.TransactionOneofCase.TransactionId)
424426
{
425427
TryFindTransaction(request.TransactionId, true);

spannerlib/wrappers/spannerlib-dotnet/spannerlib-dotnet-tests/TransactionTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Google.Cloud.SpannerLib.MockServer;
1717
using Google.Protobuf.WellKnownTypes;
1818
using Google.Rpc;
19+
using Grpc.Core;
1920

2021
namespace Google.Cloud.SpannerLib.Tests;
2122

@@ -133,4 +134,16 @@ public void TestBeginTwice([Values] LibType libType)
133134
var exception = Assert.Throws<SpannerException>(() => connection.BeginTransaction(new TransactionOptions()));
134135
Assert.That(exception.Code, Is.EqualTo(Code.FailedPrecondition));
135136
}
137+
138+
[Test]
139+
public void TestCommitFailed([Values] LibType libType)
140+
{
141+
Fixture.SpannerMock.AddOrUpdateExecutionTime(nameof(Fixture.SpannerMock.Commit), ExecutionTime.CreateException(StatusCode.FailedPrecondition, "Invalid mutations"));
142+
143+
using var pool = Pool.Create(SpannerLibDictionary[libType], ConnectionString);
144+
using var connection = pool.CreateConnection();
145+
var exception = Assert.Throws<SpannerException>(() => connection.WriteMutations(new BatchWriteRequest.Types.MutationGroup()));
146+
Assert.That(exception.Code, Is.EqualTo(Code.FailedPrecondition));
147+
}
148+
136149
}

0 commit comments

Comments
 (0)