-
astro uses https://github.com/lukeed/uvu for it's testing framework, and I was wondering if it fast-check would be useable for specifying race-condition tests? |
Beta Was this translation helpful? Give feedback.
Answered by
dubzzz
Jun 17, 2021
Replies: 1 comment 1 reply
-
Normally fast-check is supposed to be framework agnostic so yes. Actually from what I see in the documentation of // For synchronous properties
test('My property', () => {
fc.assert(fc.property(
// here your arbitraries
// here the test callback
));
});
// For asynchronous properties
test('My async property', async () => {
await fc.assert(fc.asyncProperty(
// here your arbitraries
// here the test callback
));
});
// Alternatively if you return the output of fc.assert (just hiding the async/await but uvu still sees Promises)
test('My async property', () =>
fc.assert(fc.asyncProperty(
// here your arbitraries
// here the test callback
))
); In order to use the scheduler you may have something like: test('My counter', async () => {
await fc.assert(fc.asyncProperty(fc.scheduler(), async (s) => {
// Arrange
let dbValue = 0;
const db = {
read: s.scheduleFunction(async function read() {
return dbValue;
}),
write: s.scheduleFunction(async function write(newValue: number, oldValue?: number) {
if (oldValue !== undefined && dbValue !== oldValue) return false;
dbValue = newValue;
return true;
}),
};
const counter = new Counter(db);
// Act
s.schedule(Promise.resolve('inc1')).then(() => counter.inc());
s.schedule(Promise.resolve('inc2')).then(() => counter.inc());
await s.waitAll();
// Assert
expect(dbValue).toBe(2);
}));
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
dubzzz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Normally fast-check is supposed to be framework agnostic so yes.
Actually from what I see in the documentation of
uvu
, you will have to wrap the calls to fast-check within thetest
function as follow: