-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix: avoid race condition between post-save sync & test #1679
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #1679 +/- ##
============================================
+ Coverage 20.30% 20.32% +0.01%
+ Complexity 2663 2661 -2
============================================
Files 48 48
Lines 10616 10608 -8
============================================
Hits 2156 2156
+ Misses 8460 8452 -8 ☔ View full report in Codecov by Sentry. |
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.
Didn't work for me – I can recreate the issue (with sleep(5)
) on this branch. What I observe is the post update, /post-mjml
, /test
sequence (as described), but when I add a logline after the the sleep
and the sync
method called, I see it's done after all these requests are resolved.
@adekbadek Apologies, I pasted a link to the wrong line to add the
I've updated the testing instructions above. After moving the |
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.
Works as described now!
All Submissions:
Changes proposed in this Pull Request:
Avoids a potential race condition when sending a test email. Sending a test email triggers a save, but because the campaign is synced after a save instead of on save (so that we can regenerate MJML first), and the
test
endpoint also triggers a sync, it's possible that the test request can fire its sync and send the test email before the post-save sync completes. This can result in the test email being sent with old data and content.Until this fix is deployed, editors can avoid this race condition by manually saving before sending a test email.
How to test the changes in this Pull Request:
sleep( 5 );
before this line in whichever ESP class you're testing with. This will force the post-save-sync to take 5 seconds longer to start.trunk
, make some changes to a newsletter draft's content but don't save. Then, send yourself a test email without saving first. The content in the sent test should match the content from before you clicked "Send a Test Email".a. After clicking "Send a Test Email" there should be an XHR
POST
request to an endpoint with the post ID of the post you're editing. This is the "save" request.b. Immediately after the save request finishes, you should see another
POST
request to thetest
endpoint to trigger a test email.c. Sometime after that (since you added the
sleep
delay above) you should see aPOST
request topost-mjml
, thenGET
requests toretrieve
andsync-errors
. This series of requests is the post-save sync.POST
request to thetest
endpoint doesn't start until after the lastsync-errors
request, which means that we're now waiting until the post-save sync completes before sending a test email. Because of this we can remove the extrasync
that gets triggered by thetest
endpoint handler (MC only).Other information: