Skip to content
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

Changes to handle REJECTED_TIMEDOUT #224

Merged
merged 4 commits into from
Feb 5, 2024

Conversation

favalos
Copy link
Contributor

@favalos favalos commented Feb 2, 2024

Changes to handle #206.

Copy link

codecov bot commented Feb 2, 2024

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (268c588) 63.94% compared to head (b8e9501) 64.23%.

Files Patch % Lines
test/dst/model.go 10.00% 4 Missing and 5 partials ⚠️
pkg/promise/promise.go 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #224      +/-   ##
==========================================
+ Coverage   63.94%   64.23%   +0.28%     
==========================================
  Files          92       92              
  Lines        9653     9622      -31     
==========================================
+ Hits         6173     6181       +8     
+ Misses       3043     3002      -41     
- Partials      437      439       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@favalos
Copy link
Contributor Author

favalos commented Feb 2, 2024

@dfarr Please let me know if that is what you have in mind.

I had to do some changes to the generator and model.

Let me know if any suggestions.

Thanks!

@@ -58,7 +58,7 @@ func (d *DST) Run(r *rand.Rand, api api.API, aio aio.AIO, system *system.System,
generator.AddRequest(generator.GenerateCreatePromise)
model.AddResponse(t_api.CreatePromise, model.ValidatCreatePromise)
case t_api.CompletePromise:
generator.AddRequest(generator.GenerateCancelPromise)
generator.AddRequest(generator.GenerateCompletePromise)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

test/dst/generator.go Outdated Show resolved Hide resolved
@dfarr
Copy link
Member

dfarr commented Feb 3, 2024

Looks good @favalos! I left a few comments, the main thing is to not permit a request to timeout a promise, only the server can time out a promise.

@favalos
Copy link
Contributor Author

favalos commented Feb 4, 2024

Thanks for the clarification @dfarr, I completed the changes accordingly.

Let me know if any other comments.

@@ -268,7 +269,13 @@ func (m *Model) ValidateCompletePromise(t int64, req *t_api.Request, res *t_api.
pm.promise = res.CompletePromise.Promise
return nil
case t_api.StatusCreated:
if res.CompletePromise.Promise.State != promise.Canceled {
if req.CompletePromise.State.In(promise.Resolved) && res.CompletePromise.Promise.State != promise.Resolved {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if req.CompletePromise.State.In(promise.Resolved) && res.CompletePromise.Promise.State != promise.Resolved {
if req.CompletePromise.State == promise.Resolved && res.CompletePromise.Promise.State != promise.Resolved {

if req.CompletePromise.State.In(promise.Resolved) && res.CompletePromise.Promise.State != promise.Resolved {
return fmt.Errorf("unexpected state %s after resolve promise", res.CompletePromise.Promise.State)
}
if req.CompletePromise.State.In(promise.Rejected) && res.CompletePromise.Promise.State != promise.Rejected {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if req.CompletePromise.State.In(promise.Rejected) && res.CompletePromise.Promise.State != promise.Rejected {
if req.CompletePromise.State == promise.Rejected && res.CompletePromise.Promise.State != promise.Rejected {

if req.CompletePromise.State.In(promise.Rejected) && res.CompletePromise.Promise.State != promise.Rejected {
return fmt.Errorf("unexpected state %s after reject promise", res.CompletePromise.Promise.State)
}
if req.CompletePromise.State.In(promise.Canceled) && res.CompletePromise.Promise.State != promise.Canceled {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if req.CompletePromise.State.In(promise.Canceled) && res.CompletePromise.Promise.State != promise.Canceled {
if req.CompletePromise.State == promise.Canceled && res.CompletePromise.Promise.State != promise.Canceled {

@@ -252,9 +252,10 @@ func (m *Model) ValidateCompletePromise(t int64, req *t_api.Request, res *t_api.
switch res.CompletePromise.Status {
case t_api.StatusOK:
if pm.completed() {
if !pm.idempotencyKeyForCompleteMatch(res.CompletePromise.Promise) {
if !(!req.CompletePromise.Strict && pm.promise.State == promise.Timedout) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm finding this if statement a little hard to follow, so I plugged it into a program that simplifies boolean expressions. To me the result is a little easier to understand, let me know what you think.

!(!req.CompletePromise.Strict && pm.promise.State == promise.Timedout)
  && !pm.idempotencyKeyForCompleteMatch(res.CompletePromise.Promise)

a = req.CompletePromise.Strict
b = pm.promise.State == promise.Timedout
c = pm.idempotencyKeyForCompleteMatch(res.CompletePromise.Promise)

!(!a && b) && !c
!c && !(!a && b)  put c first (I find this a little easier to read)

~c ∧ ~(~a ∧ b)    convert to boolean algebra
~c ∧ (a ∨ ~b)     an equivalent expression

!c && (a || !b)   convert back to go code, and finally put back in substitutions

!pm.idempotencyKeyForCompleteMatch(res.CompletePromise.Promise)
  && (req.CompletePromise.Strict || pm.promise.State != promise.Timedout)

Here is the equivalency proof, and here are the corresponding truth tables for both expressions:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Yes, that looks much better.

Thanks for the detailed explanation.

@favalos
Copy link
Contributor Author

favalos commented Feb 5, 2024

Let me know if any other comments.

Copy link
Member

@dfarr dfarr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@dfarr
Copy link
Member

dfarr commented Feb 5, 2024

Thanks so much again @favalos !

@dfarr dfarr merged commit 689f246 into resonatehq:main Feb 5, 2024
6 of 7 checks passed
@favalos favalos deleted the rejected_timeout_#206 branch February 5, 2024 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants