Skip to content

Commit a011764

Browse files
committed
Add check if Region is an empty string
1 parent 72d3c6e commit a011764

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

modules/GameLiftAllocator/Project/GameLiftAllocator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class GameLiftAllocator(IGameApiClient gameApiClient, IGameLiftFactory ga
4343
public async Task<AllocateResponse> Allocate(IExecutionContext context, AllocateRequest request)
4444
{
4545
// Determine AWS region from match properties or use default
46-
var region = request.MatchmakingResults.MatchProperties.GetValueOrDefault("Region")?.ToString() ?? DefaultAwsRegion;
46+
var regionValue = request.MatchmakingResults.MatchProperties.GetValueOrDefault("Region")?.ToString();
47+
var region = string.IsNullOrEmpty(regionValue) ? DefaultAwsRegion : regionValue;
4748

4849
// maxPlayers is only available in match properties when using Cloud Code hosting
4950
// It is not present when using Multiplay hosting with Cloud Code override

tests/AllocatorTests/GameLiftAllocatorTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ public async Task TestThatGameLiftCanAllocate()
5555
Assert.That(allocation.AllocationData["placementId"], Is.EqualTo("placementId"));
5656
}
5757

58+
[Test]
59+
public async Task TestThatGameLiftDefaultsRegionWhenEmptyString()
60+
{
61+
_gameLiftMock.Reset();
62+
_gameLiftMock.Setup(g => g.StartGameSessionPlacementAsync(It.IsAny<StartGameSessionPlacementRequest>(), CancellationToken.None))
63+
.ReturnsAsync(new StartGameSessionPlacementResponse
64+
{
65+
GameSessionPlacement = new GameSessionPlacement
66+
{
67+
PlacementId = "placementId",
68+
}
69+
});
70+
71+
var allocation = await _allocator.Allocate(_executionContextMock.Object, new AllocateRequest("1234",
72+
new MatchmakingResults(null, "matchId", "poolId", "poolName", "queueName", new
73+
Dictionary<string, object>{
74+
{"Region", ""},
75+
})));
76+
77+
Assert.That(allocation.AllocationData, Is.Not.Null);
78+
Assert.That(allocation.AllocationData["awsRegion"], Is.EqualTo("eu-west-2"));
79+
}
80+
5881
[Test]
5982
public async Task TestThatGameLiftCanAllocateToRegions()
6083
{

0 commit comments

Comments
 (0)