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

Prevent race conditions when loading account #868

Merged
merged 3 commits into from
Jul 1, 2022
Merged

Conversation

buberdds
Copy link
Contributor

Closes #861

@github-actions
Copy link

github-actions bot commented Jun 21, 2022

MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 6 0 0.02s
✅ GIT git_diff yes no 0.01s
✅ TYPESCRIPT eslint 6 0 0 5.91s

See errors details in artifact MegaLinter reports on CI Job page
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

@buberdds buberdds requested a review from lukaw3d June 21, 2022 14:40
@codecov
Copy link

codecov bot commented Jun 21, 2022

Codecov Report

Merging #868 (0766178) into master (4f12054) will increase coverage by 0.12%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #868      +/-   ##
==========================================
+ Coverage   88.29%   88.41%   +0.12%     
==========================================
  Files          97       97              
  Lines        1606     1606              
  Branches      336      336              
==========================================
+ Hits         1418     1420       +2     
+ Misses        188      186       -2     
Flag Coverage Δ
cypress 60.72% <85.71%> (ø)
jest 74.67% <85.71%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/app/state/account/saga.ts 69.04% <100.00%> (ø)
src/app/state/network/saga.ts 100.00% <100.00%> (+8.69%) ⬆️
src/app/state/staking/saga.ts 93.82% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f12054...0766178. Read the comment docs.

Comment on lines +7 to +13
testSaga(accountSaga)
.next()
.fork(refreshAccountOnTransaction)
.next()
.takeLatest(accountActions.fetchAccount, loadAccount)
.next()
.isDone()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is a useful test.

I'd rather see approximately

expectSaga(stakingSaga)
  .provide(getAccount, () => delay(10*Math.random()))
  .put(fetchAccount('a'))
  .put(fetchAccount('b'))
  .hasFinalState({ address: 'b' })
  .run()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this unit test if valid unless I am missing something, but I am following one of redux saga test plan pattern. I am adding a unit test not integration test. Unit test is testing a watcher saga only and it doesn't care about integration with other parts of code. The bug exists because of using a wrong effect creator. Unit test is validating if a correct effect creator is used so it covers current bug/potential regression bug.

Copy link
Member

Choose a reason for hiding this comment

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

This unit test is essentially "did source code change" and it will break on many non-regressions.

expect(accountSaga.toString()).toBe(`
  export function* accountSaga() {
    yield* fork(refreshAccountOnTransaction)
    yield* takeLatest(actions.fetchAccount, loadAccount)
  }
`)

testSaga becomes interesting when unit testing with different inputs in .next(_), so it tests behavior, instead of implementation.

src/app/state/staking/saga.ts Outdated Show resolved Hide resolved
@buberdds buberdds force-pushed the mz/preventRaceCond branch 3 times, most recently from 5f8aa57 to 3a6f264 Compare June 22, 2022 12:59
@buberdds buberdds merged commit 1b03ad7 into master Jul 1, 2022
@buberdds buberdds deleted the mz/preventRaceCond branch July 1, 2022 08:45
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.

Prevent race conditions
2 participants