Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,57 @@ await Assert.ThrowsAsync<TaskCanceledException>(async () =>
});
}

/// <summary>
/// Verifies Steam launch setup is serialized across profiles that share an installation.
/// </summary>
/// <returns>The async task.</returns>
[Fact]
public async Task LaunchProfileAsync_ConcurrentSteamProfilesSharingInstallation_SerializesSetup()
{
// Arrange
var firstProfile = CreateTestProfile();
firstProfile.UseSteamLaunch = true;
var secondProfile = CreateTestProfile();
secondProfile.UseSteamLaunch = true;
var cleanupStarted = new TaskCompletionSource<bool>(
TaskCreationOptions.RunContinuationsAsynchronously);
var releaseCleanup = new TaskCompletionSource<bool>(
TaskCreationOptions.RunContinuationsAsynchronously);
var cleanupCalls = 0;

_steamLauncherMock.Setup(x => x.CleanupGameDirectoryAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<CancellationToken>()))
.Returns(async () =>
{
Interlocked.Increment(ref cleanupCalls);
cleanupStarted.TrySetResult(true);
await releaseCleanup.Task;
return OperationResult<bool>.CreateFailure("Injected cleanup stop.");
});

// Act
var firstLaunch = _gameLauncher.LaunchProfileAsync(firstProfile);
await cleanupStarted.Task.WaitAsync(TimeSpan.FromSeconds(5));
var secondLaunch = _gameLauncher.LaunchProfileAsync(secondProfile);

try
{
await Task.Delay(TimeSpan.FromMilliseconds(250));
Assert.Equal(1, Volatile.Read(ref cleanupCalls));
}
finally
{
releaseCleanup.TrySetResult(true);
}

// Assert
var results = await Task.WhenAll(firstLaunch, secondLaunch);
Assert.All(results, result => Assert.False(result.Success));
Assert.Equal(2, Volatile.Read(ref cleanupCalls));
}

/// <summary>
/// Launches a profile with empty enabled content and asserts success.
/// </summary>
Expand Down Expand Up @@ -813,4 +864,4 @@ private static GameProfile CreateTestProfile()
EnabledContentIds = ["1.0.genhub.mod.test"],
};
}
}
}
Loading
Loading