-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor entity cleanup test to make it less flakey #2871
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5065,6 +5065,8 @@ public async Task DurableEntity_CleanEntityStorage(string storageProvider) | |
var orchestrationA = $"{prefix}-A"; | ||
var orchestrationB = $"{prefix}-B"; | ||
|
||
// PART 1: Test removal of empty entities | ||
|
||
// create an empty entity | ||
var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.CreateEmptyEntities), new EntityId[] { emptyEntityId }, this.output); | ||
var status = await client.WaitForCompletionAsync(this.output); | ||
|
@@ -5084,28 +5086,38 @@ public async Task DurableEntity_CleanEntityStorage(string storageProvider) | |
var result = await client.InnerClient.ListEntitiesAsync(query, CancellationToken.None); | ||
Assert.Contains(result.Entities, s => s.EntityId.Equals(emptyEntityId)); | ||
|
||
// test removal of empty entity | ||
var response = await client.InnerClient.CleanEntityStorageAsync(removeEmptyEntities: true, releaseOrphanedLocks: false, CancellationToken.None); | ||
Assert.Equal(1, response.NumberOfEmptyEntitiesRemoved); | ||
Assert.Equal(0, response.NumberOfOrphanedLocksRemoved); | ||
|
||
// check that the empty entity record has been removed from storage | ||
result = await client.InnerClient.ListEntitiesAsync(query, CancellationToken.None); | ||
Assert.DoesNotContain(result.Entities, s => s.EntityId.Equals(emptyEntityId)); | ||
|
||
// PART 2: Test recovery from orphaned locks | ||
|
||
// run an orchestration A that leaves an orphaned lock | ||
TestDurableClient clientA = await host.StartOrchestratorAsync(nameof(TestOrchestrations.LockThenFailReplay), (orphanedEntityId, true), this.output, orchestrationA); | ||
status = await clientA.WaitForCompletionAsync(this.output); | ||
|
||
// run an orchestration B that queues behind A for the lock (and thus gets stuck) | ||
TestDurableClient clientB = await host.StartOrchestratorAsync(nameof(TestOrchestrations.LockThenFailReplay), (orphanedEntityId, false), this.output, orchestrationB); | ||
|
||
// remove empty entity and release orphaned lock | ||
var response = await client.InnerClient.CleanEntityStorageAsync(true, true, CancellationToken.None); | ||
await Task.Delay(TimeSpan.FromMinutes(1)); // wait for a stable entity executionID, needed until https://github.com/Azure/durabletask/pull/1128 is merged | ||
|
||
// remove release orphaned lock to unblock orchestration B | ||
// Note: do NOT remove empty entities yet: we want to keep the empty entity so it can unblock orchestration B | ||
response = await client.InnerClient.CleanEntityStorageAsync(removeEmptyEntities: false, releaseOrphanedLocks: true, CancellationToken.None); | ||
Assert.Equal(1, response.NumberOfOrphanedLocksRemoved); | ||
Assert.Equal(1, response.NumberOfEmptyEntitiesRemoved); | ||
Assert.Equal(0, response.NumberOfEmptyEntitiesRemoved); | ||
|
||
// wait for orchestration B to complete, now that the lock has been released | ||
status = await clientB.WaitForCompletionAsync(this.output); | ||
Assert.True(status.RuntimeStatus == OrchestrationRuntimeStatus.Completed); | ||
|
||
// check that the empty entity record has been removed from storage | ||
result = await client.InnerClient.ListEntitiesAsync(query, CancellationToken.None); | ||
Assert.DoesNotContain(result.Entities, s => s.EntityId.Equals(emptyEntityId)); | ||
|
||
Comment on lines
-5103
to
-5106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was moved to earlier in the test, lines ~5095 to 5097 |
||
// clean again to remove the orphaned entity which is now empty also | ||
response = await client.InnerClient.CleanEntityStorageAsync(true, true, CancellationToken.None); | ||
response = await client.InnerClient.CleanEntityStorageAsync(removeEmptyEntities: true, releaseOrphanedLocks: true, CancellationToken.None); | ||
Assert.Equal(0, response.NumberOfOrphanedLocksRemoved); | ||
Assert.Equal(1, response.NumberOfEmptyEntitiesRemoved); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,14 +411,14 @@ public async Task WaitForCompletionOrCreateCheckStatusResponseAsync_Returns_HTTP | |
TaskHub = TestConstants.TaskHub, | ||
ConnectionName = TestConstants.ConnectionName, | ||
}, | ||
TimeSpan.FromSeconds(10), | ||
TimeSpan.FromSeconds(15), | ||
TimeSpan.FromSeconds(3)); | ||
stopwatch.Stop(); | ||
Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode); | ||
var content = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
var value = JsonConvert.DeserializeObject<string>(content); | ||
Assert.Equal("Hello Tokyo!", value); | ||
Assert.True(stopwatch.Elapsed < TimeSpan.FromSeconds(10)); | ||
Assert.True(stopwatch.Elapsed < TimeSpan.FromSeconds(15)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GitHub actions sometimes run slightly slower, so needed this extra buffer to pass the test |
||
} | ||
|
||
[Fact] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this used to occur later in the test, but there was no clear reason to do that. So I've moved this earlier, which separates the tests into 2 distinct parts: (1) testing the deletion or empty entities, and (2) testing the releasing of orphaned locks. This should make the test easier to read, I hope