-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from tjenkinson/automatic-forkable-reader-gc
Switch to `forkable-iterator` package so that GC can be automatic on `ForkableReader`
- Loading branch information
Showing
10 changed files
with
61 additions
and
131 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,9 @@ | ||
afterAll(() => { | ||
// prevents | ||
// "A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them." | ||
// happening | ||
// This seems to be because the process is taking too long to terminate, as a result of GC taking too long during the timeout period | ||
// Doing this moves the GC to before the request for the process to stop where the timeout is running | ||
// See https://github.com/facebook/jest/pull/13139 | ||
global.gc?.(); | ||
}); |
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 |
---|---|---|
@@ -1,48 +1,23 @@ | ||
import { | ||
buildArrayReader, | ||
buildForkableReader, | ||
ForkableReader, | ||
} from './reader'; | ||
import { buildArrayReader, chainReaders, emptyReader } from './reader'; | ||
|
||
describe('Reader', () => { | ||
describe('ForkableReader', () => { | ||
let reader: ForkableReader<number, void>; | ||
beforeEach(() => { | ||
reader = buildForkableReader(buildArrayReader([1, 2, 3])); | ||
}); | ||
|
||
describe('chainReaders()', () => { | ||
it('yields the correct items', () => { | ||
const fork = reader.fork(); | ||
expect(fork.next().value).toBe(1); | ||
expect(fork.next().value).toBe(2); | ||
|
||
const reader = chainReaders([ | ||
buildArrayReader([0, 1]), | ||
buildArrayReader([2, 3]), | ||
]); | ||
expect(reader.next().value).toBe(0); | ||
expect(reader.next().value).toBe(1); | ||
|
||
const fork2 = reader.fork(); | ||
expect(reader.next().value).toBe(2); | ||
|
||
expect(fork2.next().value).toBe(2); | ||
|
||
expect(reader.next().value).toBe(3); | ||
expect(reader.next().value).toBe(undefined); | ||
|
||
expect(fork.next().value).toBe(3); | ||
expect(fork.next().value).toBe(undefined); | ||
|
||
expect(fork2.next().value).toBe(3); | ||
expect(fork2.next().value).toBe(undefined); | ||
}); | ||
|
||
it('throws if next() is called after dispose', () => { | ||
reader.dispose(); | ||
expect(() => reader.next()).toThrowError( | ||
'Internal error: reader disposed' | ||
); | ||
expect(reader.next().done).toBe(true); | ||
}); | ||
}); | ||
|
||
it('allows dispose() to be called multiple times', () => { | ||
reader.dispose(); | ||
reader.dispose(); | ||
describe('emptyReader()', () => { | ||
it('is immediately done', () => { | ||
expect(emptyReader().next().done).toBe(true); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.