Skip to content

Commit 3c28539

Browse files
committed
improve job state testing
1 parent 796751f commit 3c28539

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

RefreshTests.GameServer/Tests/Workers/JobStateTests.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ public void ReExecutesMigrationJobAfterRollbackAndReupdate()
113113
Assert.That(firstLevelMigrated!.Title, Does.EndWith(" test"));
114114
context.Database.Refresh();
115115

116-
// While we do automatically apply whatever new change we've migrated existing entities to for real migrations (photo subjects, player limits etc.),
117-
// we don't auto-append " test" to new levels here, so we can safely create this level now, which would need migration aswell because of this.
116+
// We can ignore the fact that this level's title won't end on " test", since when we add a real migration job for a certain entity,
117+
// we also adjust that entity's creation/update methods in order to apply whatever change we want to new entities aswell.
118+
// We don't do it here, and it doesn't matter in this test.
118119
GameLevel secondLevel = context.CreateLevel(user);
119120
// Should skip job because it's still "complete", so the new level won't be migrated.
120121
manager.RunWorkCycle();
@@ -134,18 +135,24 @@ public void ReExecutesMigrationJobAfterRollbackAndReupdate()
134135
// 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
135136
// auto-removed by WorkerManager.Start() in real cases.
136137
manager = new(Logger, dataStore, context.DatabaseProvider);
138+
GameLevel thirdLevel = context.CreateLevel(user);
139+
137140
manager.RemoveUnusedJobStates();
138141
manager.RunWorkCycle();
139142
context.Database.Refresh();
140143

141-
// Second level was not migrated, and the job state was removed
144+
// No new levels were migrated, and the job state was removed
142145
stateObject = context.Database.GetJobState(typeof(TestMigrationJob).Name, typeof(MigrationJobState), WorkerClass.Refresh);
143146
Assert.That(stateObject, Is.Null);
144147

145148
GameLevel? secondLevelMigrated = context.Database.GetLevelById(secondLevel.LevelId);
146149
Assert.That(secondLevelMigrated, Is.Not.Null);
147150
Assert.That(secondLevelMigrated!.Title, Does.Not.EndWith(" test"));
148151

152+
GameLevel? thirdLevelMigrated = context.Database.GetLevelById(thirdLevel.LevelId);
153+
Assert.That(thirdLevelMigrated, Is.Not.Null);
154+
Assert.That(thirdLevelMigrated!.Title, Does.Not.EndWith(" test"));
155+
149156
// Now simulate a re-update, where the job is in the WorkerManager again
150157
manager = new(Logger, dataStore, context.DatabaseProvider);
151158
job = new();
@@ -159,10 +166,14 @@ public void ReExecutesMigrationJobAfterRollbackAndReupdate()
159166

160167
jobState = (MigrationJobState)stateObject!;
161168
Assert.That(jobState.Complete, Is.True);
162-
Assert.That(jobState.Processed, Is.EqualTo(2));
169+
Assert.That(jobState.Processed, Is.EqualTo(3));
163170

164171
secondLevelMigrated = context.Database.GetLevelById(secondLevel.LevelId);
165172
Assert.That(secondLevelMigrated, Is.Not.Null);
166173
Assert.That(secondLevelMigrated!.Title, Does.EndWith(" test"));
174+
175+
thirdLevelMigrated = context.Database.GetLevelById(thirdLevel.LevelId);
176+
Assert.That(thirdLevelMigrated, Is.Not.Null);
177+
Assert.That(thirdLevelMigrated!.Title, Does.EndWith(" test"));
167178
}
168179
}

0 commit comments

Comments
 (0)