Skip to content

Commit

Permalink
Merge pull request #57 from hendrikdevloed/feature/53/GetWorkStatus
Browse files Browse the repository at this point in the history
Allow returning NotStarted from GetWorkStatus
  • Loading branch information
Kritner authored Feb 5, 2024
2 parents 76715ba + 7a0250c commit 771ab84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
12 changes: 1 addition & 11 deletions src/Orleans.SyncWork/SyncWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,7 @@ public Task<bool> Start(TRequest request)
}

/// <inheritdoc />
public Task<SyncWorkStatus> GetWorkStatus()
{
if (_status == SyncWorkStatus.NotStarted)
{
Logger.LogError("{Method} was in a status of {WorkStatus}", nameof(GetWorkStatus), SyncWorkStatus.NotStarted);
DeactivateOnIdle();
throw new InvalidStateException(_status);
}

return Task.FromResult(_status);
}
public Task<SyncWorkStatus> GetWorkStatus() => Task.FromResult(_status);

/// <inheritdoc />
public Task<Exception?> GetException()
Expand Down
15 changes: 3 additions & 12 deletions test/Orleans.SyncWork.Tests/SyncWorkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,13 @@ public async Task WhenGivenLargeNumberOfRequests_SystemShouldNotBecomeOverloaded
tasks.Select(task => task.Result).Should().OnlyContain(result => true);
}

/// <summary>
/// This is to protect against cases where the silo restarts and the instance state is lost.
/// The class' intention is to always start work with a request, request the status, retrieve the result.
///
/// If the silo restarts, the "worked" task is lost, and status reset to "NotStarted", throwing in that scenario
/// allows for a faster turnaround on the side of consumers in order to handle the silo restart - probably by
/// redispatching the work.
/// </summary>
[Fact]
public async Task WhenGrainNotStarted_ShouldThrowOnAttemptingToRetrieveStatus()
public async Task WhenGrainNotStarted_ShouldReturnStatusNotStartedOnGetStatus()
{
var grain = Cluster.GrainFactory.GetGrain<ISyncWorker<TestDelaySuccessRequest, TestDelaySuccessResult>>(Guid.NewGuid());

var action = new Func<Task>(async () => await grain.GetWorkStatus());

await action.Should().ThrowAsync<InvalidStateException>();
var status = await grain.GetWorkStatus();
status.Should().Be(Enums.SyncWorkStatus.NotStarted);
}

[Fact]
Expand Down

0 comments on commit 771ab84

Please sign in to comment.