Skip to content

Commit

Permalink
tinker with timers
Browse files Browse the repository at this point in the history
  • Loading branch information
urugator committed Aug 12, 2023
1 parent 20a7106 commit 1323692
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ test("uncommitted components should not leak observations", async () => {
)

// Allow gc to kick in in case to let finalization registry cleanup
await new Promise(resolve => setTimeout(resolve, 0))
await Promise.resolve()
gc()
await new Promise(resolve => setTimeout(resolve, 0))
// Can take a while (especially on CI) before gc actually calls the registry
await waitFor(
() => {
Expand All @@ -55,7 +54,7 @@ test("uncommitted components should not leak observations", async () => {
},
{
timeout: 10_000,
interval: 200
interval: 150
}
)
})
13 changes: 5 additions & 8 deletions packages/mobx-react/__tests__/finalizationRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import { observer } from "../src"

afterEach(cleanup)

function sleep(time: number) {
return new Promise<void>(res => {
setTimeout(res, time)
})
}

// TODO remove once https://github.com/mobxjs/mobx/pull/3620 is merged.
declare class WeakRef<T> {
constructor(object: T)
Expand Down Expand Up @@ -80,9 +74,12 @@ test("should not prevent GC of uncomitted components", async () => {
expect(aConstructorCount).toBe(2)
expect(aMountCount).toBe(1)

await Promise.resolve()
gc()
await sleep(50)
expect(firstARef!.deref()).toBeUndefined()
await waitFor(() => expect(firstARef!.deref()).toBeUndefined(), {
timeout: 10_000,
interval: 150
})

unmount()
})
13 changes: 9 additions & 4 deletions packages/mobx/__tests__/v5/base/typescript-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ test("computed setter should succeed", () => {
})

test("atom clock example", done => {
// TODO randomly fails, rework
let ticks = 0
const time_factor = process.env.CI === "true" ? 300 : 100 // speed up / slow down tests

Expand Down Expand Up @@ -1824,12 +1825,16 @@ test("sync when can be aborted", async () => {
const x = mobx.observable.box(1)

const ac = new AbortController()
mobx.when(() => x.get() === 3, () => {
fail("should abort")
}, { signal: ac.signal })
mobx.when(
() => x.get() === 3,
() => {
fail("should abort")
},
{ signal: ac.signal }
)
ac.abort()

x.set(3);
x.set(3)
})

test("it should support asyncAction as decorator (ts)", async () => {
Expand Down

0 comments on commit 1323692

Please sign in to comment.