mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Evict Metro bundle graphs after each Fantom test to prevent OOM (#56514)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56514 Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D101652820 fbshipit-source-id: f7608fbf92a8fd2928434e74ad03bfc01b318d20
This commit is contained in:
1 parent
65c561e195
commit
3fb1fea57e
2 files changed
+36
-2
No files matched your search
+12
-1
@@ -28,6 +28,8 @@ export async function createBundle(options: BundleOptions): Promise<void> {
|
||||
let lastBundleResult;
|
||||
let lastBundleError;
|
||||
|
||||
const bundleURL = getBundleURL(options);
|
||||
|
||||
// Retry in case Metro hasn't seen the changes in the filesystem yet.
|
||||
// TODO(T231910841): Remove this when Metro fixes consistency issues when resolving HTTP requests.
|
||||
let attemps = 0;
|
||||
@@ -40,7 +42,7 @@ export async function createBundle(options: BundleOptions): Promise<void> {
|
||||
lastBundleResult = null;
|
||||
|
||||
try {
|
||||
lastBundleResult = await fetch(getBundleURL(options));
|
||||
lastBundleResult = await fetch(bundleURL);
|
||||
} catch (e) {
|
||||
lastBundleError = e;
|
||||
}
|
||||
@@ -72,6 +74,15 @@ export async function createBundle(options: BundleOptions): Promise<void> {
|
||||
await lastBundleResult.text(),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
// Each test uses a unique entrypoint, so the bundle graph will never be
|
||||
// requested again. Send DELETE to evict Metro's cached dependency graph
|
||||
// and delta calculator for this bundle, freeing the memory.
|
||||
try {
|
||||
await fetch(bundleURL, {method: 'DELETE'});
|
||||
} catch {
|
||||
// Best-effort cleanup — don't fail the test if eviction fails.
|
||||
}
|
||||
}
|
||||
|
||||
export async function createSourceMap(options: BundleOptions): Promise<void> {
|
||||
|
||||
@@ -14,6 +14,8 @@ type MetroServer = NonNullable<RunServerResult?.['httpServer']>;
|
||||
|
||||
declare var __FANTOM_METRO_SERVER__: ?RunServerResult;
|
||||
|
||||
const SHUTDOWN_TIMEOUT_MS = 5_000;
|
||||
|
||||
function getMetroServer(): ?MetroServer {
|
||||
return typeof __FANTOM_METRO_SERVER__ !== 'undefined' &&
|
||||
__FANTOM_METRO_SERVER__ != null
|
||||
@@ -32,7 +34,11 @@ export default async function globalTeardown(
|
||||
}
|
||||
|
||||
async function stopMetroServer(metroServer: MetroServer): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!metroServer.listening) {
|
||||
return;
|
||||
}
|
||||
|
||||
const closed = new Promise<void>((resolve, reject) => {
|
||||
metroServer.close(error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
@@ -41,4 +47,21 @@ async function stopMetroServer(metroServer: MetroServer): Promise<void> {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// $FlowFixMe[method-unbinding] Node 18.2+ API
|
||||
if (typeof metroServer.closeIdleConnections === 'function') {
|
||||
metroServer.closeIdleConnections();
|
||||
}
|
||||
|
||||
const timeout = new Promise<void>(resolve => {
|
||||
setTimeout(() => {
|
||||
// $FlowFixMe[method-unbinding] Node 18.2+ API
|
||||
if (typeof metroServer.closeAllConnections === 'function') {
|
||||
metroServer.closeAllConnections();
|
||||
}
|
||||
resolve();
|
||||
}, SHUTDOWN_TIMEOUT_MS);
|
||||
});
|
||||
|
||||
await Promise.race([closed, timeout]);
|
||||
}
|
||||
Reference in new issue
Block a user