Add some debug messages for random test failures. (#18216)

This commit is contained in:
Leon Friedrich
2023-07-24 05:22:57 +12:00
committed by GitHub
parent c6d2dd6c7b
commit 7786daa20e
3 changed files with 27 additions and 2 deletions

View File

@@ -63,7 +63,12 @@ public sealed class UserDbDataManager
public bool IsLoadComplete(IPlayerSession session)
{
return _users[session.UserId].Task.IsCompleted;
return GetLoadTask(session).IsCompleted;
}
public Task GetLoadTask(IPlayerSession session)
{
return _users[session.UserId].Task;
}
private sealed record UserData(CancellationTokenSource Cancel, Task Task);

View File

@@ -120,9 +120,28 @@ namespace Content.Server.GameTicking
async void SpawnWaitDb()
{
// Temporary debugging code to fix a random test failures
var initialStatus = _userDb.GetLoadTask(session).Status;
var prefsLoaded = _prefsManager.HavePreferencesLoaded(session);
DebugTools.Assert(session.Status == SessionStatus.InGame);
await _userDb.WaitLoadComplete(session);
try
{
SpawnPlayer(session, EntityUid.Invalid);
}
catch (Exception e)
{
Log.Error($"Caught exception while trying to spawn a player.\n" +
$"Initial DB task status: {initialStatus}\n" +
$"Prefs initially loaded: {prefsLoaded}\n" +
$"DB task status: {_userDb.GetLoadTask(session).Status}\n" +
$"Prefs loaded: {_prefsManager.HavePreferencesLoaded(session)}\n" +
$"Exception: \n{e}");
throw;
}
}
async void SpawnObserverWaitDb()
{

View File

@@ -17,5 +17,6 @@ namespace Content.Server.Preferences.Managers
bool TryGetCachedPreferences(NetUserId userId, [NotNullWhen(true)] out PlayerPreferences? playerPreferences);
PlayerPreferences GetPreferences(NetUserId userId);
IEnumerable<KeyValuePair<NetUserId, ICharacterProfile>> GetSelectedProfilesForPlayers(List<NetUserId> userIds);
bool HavePreferencesLoaded(IPlayerSession session);
}
}