-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clear programs cache if >90% of heap is used (#643)
## PR Checklist - [x] Addresses an existing open issue: fixes #642 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/blob/main/.github/CONTRIBUTING.md) were taken ## Overview I played around with different strategies a bit, but ended up doing basically the same thing as microsoft/DefinitelyTyped-tools#1024. Therefore: Co-authored-by: Andrew Branch <andrew@wheream.io>
- Loading branch information
1 parent
7ab053e
commit 9596a34
Showing
2 changed files
with
60 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import ts from "typescript"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { getProgramForVersion } from "./programs.js"; | ||
|
||
const mockGetHeapStatistics = vi.fn<() => Record<string, number>>(); | ||
|
||
vi.mock("node:v8", () => ({ | ||
get default() { | ||
return { getHeapStatistics: mockGetHeapStatistics }; | ||
}, | ||
})); | ||
|
||
const originalProgram = ts.createProgram({ | ||
options: {}, | ||
rootNames: [], | ||
}); | ||
|
||
function actGetProgramForVersion() { | ||
return getProgramForVersion("tsconfig.json", ts, "current", originalProgram); | ||
} | ||
|
||
describe("getProgramForVersion", () => { | ||
it("reuses old programs when <90% of the heap is used", () => { | ||
mockGetHeapStatistics.mockReturnValue({ | ||
heap_size_limit: 100, | ||
used_heap_size: 90, | ||
}); | ||
|
||
const programA = actGetProgramForVersion(); | ||
const programB = actGetProgramForVersion(); | ||
|
||
expect(programA).toBe(programB); | ||
}); | ||
|
||
it("does not reuse old programs when >90% of the heap is used", () => { | ||
mockGetHeapStatistics.mockReturnValue({ | ||
heap_size_limit: 100, | ||
used_heap_size: 91, | ||
}); | ||
|
||
const programA = actGetProgramForVersion(); | ||
const programB = actGetProgramForVersion(); | ||
|
||
expect(programA).not.toBe(programB); | ||
}); | ||
}); |
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