-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: All list method call are sequential. This will prevent unwanted…
… race conditions and enforce data accuracy
- Loading branch information
Showing
5 changed files
with
159 additions
and
69 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import test from "tape" | ||
import { createStore, combineReducers } from "redux" | ||
|
||
import { buildList } from ".." | ||
|
||
test("Read - race conditions", async t => { | ||
let callCount = 0 | ||
|
||
// WHAT TO TEST | ||
const todos = buildList({ | ||
name: "READ_RACE_TODOS", | ||
read: () => { | ||
callCount++ | ||
|
||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve([ | ||
{ id: 1, name: "lorem ipsum" }, | ||
{ id: 2, name: "foo bar" }, | ||
]) | ||
}, 100) | ||
}) | ||
}, | ||
}) | ||
|
||
// Redux store | ||
const store = createStore( | ||
combineReducers({ | ||
[todos.name]: todos.reducer, | ||
}) | ||
) | ||
|
||
todos.set({ dispatch: store.dispatch }) | ||
|
||
await Promise.all([ | ||
todos.read(), | ||
todos.read(), | ||
todos.read(), | ||
todos.read(), | ||
todos.read(), | ||
todos.read(), | ||
new Promise(resolve => { | ||
// run another .read after the others ended | ||
setTimeout(() => { | ||
resolve(todos.read()) | ||
}, 150) | ||
}), | ||
]) | ||
|
||
t.equals( | ||
callCount, | ||
2, | ||
"Multiple same signature calls should not trigger until first one ended" | ||
) | ||
|
||
t.end() | ||
}) |
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
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