-
Notifications
You must be signed in to change notification settings - Fork 120
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 replication in tests #2614
Fix replication in tests #2614
Conversation
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.
Thank you!!! This is a big breakthrough. Even though all the act
and pending timers are verbose, it's great that we have a working baseline now. I'm happy to discuss any ideas you have for abstracting away some of the async complexity.
src/components/__tests__/Bullet.ts
Outdated
@@ -26,6 +26,8 @@ describe('render', () => { | |||
}), | |||
]) | |||
|
|||
await act(async () => vi.runOnlyPendingTimersAsync()) |
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.
FYI This can be shortened to:
await act(vi.runOnlyPendingTimersAsync)
@@ -45,10 +42,12 @@ it('disable isLoading after initialize', async () => { | |||
}) | |||
|
|||
// y-indexeddb breaks tests | |||
it.skip('load thought', async () => { | |||
it('load thought', async () => { |
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.
Very exciting! It's been a long time since these tests have been operational. It will also allow us to write new tests that cover more complex persistence behavior.
Replication via
thoughtspace.ts
was broken in the tests, so replication was explicitly prevented when running the tests. This appears to have allowed the majority of the tests to work since replication is not required for a lot of them but some tests that rely on the replication failed and were skipped.The primary problem appears to be that
vi.runPendingTimers
does not appear to work for database replication tasks;await vi.runPendingTimers
is required. I am not entirely sure why this is because I do not really understand the internals here.Once this was fixed it led to a cascade of other problems that had to be fixed. My guess is that once replication was enabled, asynchronous background functionality that was not being triggered suddenly got enabled and was causing asynchronous stuff to run after the tests had completed. This required going back and ensuring that all of that activity was properly awaited.
Given the volume of the problems I did not spend a significant amount of time analyzing each issue so some of the solutions may be non-optimal, but I think we should spend some time trying to decide if there are better ways to solve the problems that all the asynchronous execution seems to be causing before analyzing every test problem.
A miscellaneous note: I had to move some tests around; it looks like the tests that rely on
createTestStore
may not be getting completely cleaned up and thus leave remnants in the database that persist to later tests, causing them to break. I think there's probably a pretty easy fix here but it made sense to go with the quicker fix (move the breaking tests to the top of the file) instead of me figuring out the better fix.The operative changes are in
thoughtspace.ts
andcreateTestStore.ts
; most of the other changes are essentially making sure the fake timers are properly moved forward.