Skip to content

Commit e4fdf85

Browse files
committed
the answer was actually a lot simpler, but good luck figuring it out
1 parent 3c28539 commit e4fdf85

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

Refresh.Database/GameDatabaseContext.Levels.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ public GameLevel AddLevel(ISerializedPublishLevel createInfo, TokenGame game, Ga
5858
UpdateDate = timestamp,
5959
};
6060

61+
// This prevents EF from trying to INSERT both the user and their stats in unit tests,
62+
// just because of us setting the level.Publisher reference, and throwing a duplicate key exception that way.
63+
this.Entry(level.Publisher).State = EntityState.Unchanged;
64+
6165
this.ApplyLevelMetadataFromAttributes(level);
6266
this.GameLevels.Add(level);
6367

64-
// Seems unnecessary, but prevents EF from trying to INSERT both unconditionally in unit tests
65-
this.GameUsers.Update(publisher);
66-
if (publisher.Statistics != null)
67-
this.GameUserStatistics.Update(publisher.Statistics);
68-
6968
this.SaveChanges();
7069

7170
this.WriteEnsuringStatistics(publisher, () =>

RefreshTests.GameServer/Tests/Workers/JobStateTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public void ReExecutesMigrationJobAfterRollbackAndReupdate()
135135
// Simulate a roll-back, meaning the job wouldn't be in the WorkerManager anymore, so no migrations will happen, and the job state would be
136136
// auto-removed by WorkerManager.Start() in real cases.
137137
manager = new(Logger, dataStore, context.DatabaseProvider);
138+
context.Database.Refresh();
138139
GameLevel thirdLevel = context.CreateLevel(user);
139140

140141
manager.RemoveUnusedJobStates();

0 commit comments

Comments
 (0)