Skip to content

Commit

Permalink
test: add persistent cache test (#8890)
Browse files Browse the repository at this point in the history
* test: add persistent cache test

* test: update snapshot
  • Loading branch information
jerrykingxyz authored Dec 30, 2024
1 parent 515e650 commit 28f2169
Show file tree
Hide file tree
Showing 26 changed files with 296 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/processor/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CacheProcessor<T extends ECompilerType> extends BasicProcessor<T> {
directory = experiments.cache.storage?.directory || directory;
}
removeSync(
path.join(context.getSource(), directory || "node_modules/.cache")
path.resolve(context.getSource(), directory || "node_modules/.cache")
);

await super.build(context);
Expand Down
4 changes: 3 additions & 1 deletion packages/rspack-test-tools/src/runner/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ export class CacheRunnerFactory<
await compiler.close();
compiler.createCompiler();

const oldChangedFiles = hotUpdateContext.changedFiles;
await Promise.all(
hotUpdateContext.changedFiles.map(async file => {
oldChangedFiles.map(async file => {
await refreshModifyTime(file);
})
);
hotUpdateContext.changedFiles = [];
hotUpdateContext.updateIndex++;
const stats = await compiler.build();
hotUpdateContext.changedFiles = oldChangedFiles;
if (!stats) {
throw new Error("Should generate stats during build");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import value from "./file";

it("should store and resume asset parser and generator states", async () => {
it("should basic test work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import value from "./file";

it("should build dependencies work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(3);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require("path");
const fs = require("fs/promises");

let content = 1;

const buildDependency = path.join(__dirname, "test.log");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
buildDependencies: [buildDependency],
snapshot: {
immutablePaths: [path.join(__dirname, "./file.js")]
}
}
},
plugins: [
{
apply(compiler) {
compiler.hooks.beforeCompile.tapPromise(
"Test Plugin",
async function () {
await fs.writeFile(buildDependency, String(content));
content++;
}
);
}
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import value from "./file";

it("should version work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(3);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require("path");

let version = 1;

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
snapshot: {
immutablePaths: [path.join(__dirname, "./file.js")]
}
}
},
plugins: [
{
apply(compiler) {
compiler.hooks.beforeCompile.tap("Test Plugin", function () {
compiler.options.experiments.cache.version = String(version);
version++;
});
}
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import value from "./file";

it("should snapshot immutable-paths work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(2);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require("path");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
snapshot: {
immutablePaths: [path.join(__dirname, "./file.js")]
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import value from "./test_lib";

it("should snapshot managed-paths work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(2);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require("path");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
snapshot: {
managedPaths: [path.join(__dirname, "./test_lib")]
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "test_lib",
"version": "0.0.1",
"main": "./file.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import value, { changed } from "./test_lib";

it("should snapshot unmanaged-paths work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
expect(changed).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
expect(changed).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(2);
expect(changed).toBe(3);
await NEXT_HMR();
expect(value).toBe(4);
expect(changed).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require("path");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
snapshot: {
managedPaths: [path.join(__dirname, "./test_lib")],
unmanagedPaths: [path.join(__dirname, "./test_lib/changed.js")]
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import changed from "./changed";
export { changed };
export default 1;
---
import changed from "./changed";
export { changed };
export default 2;
---
import changed from "./changed";
export { changed };
export default 3;
---
import changed from "./changed";
export { changed };
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "test_lib",
"version": "0.0.1",
"main": "./file.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default 1;
---
export default 2;
---
export default 3;
---
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import value from "./file";

it("should storage directory work", async () => {
if (COMPILER_INDEX == 0) {
expect(value).toBe(1);
await NEXT_HMR();
expect(value).toBe(2);
await NEXT_START();
}
if (COMPILER_INDEX == 1) {
expect(value).toBe(3);
await NEXT_HMR();
expect(value).toBe(4);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const path = require("path");
const fs = require("fs/promises");

const cacheDir = path.join(__dirname, "node_modules/.cache/test/");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
context: __dirname,
experiments: {
cache: {
type: "persistent",
storage: {
type: "filesystem",
directory: cacheDir
}
}
},
plugins: [
{
apply(compiler) {
compiler.hooks.done.tapPromise("Test Plugin", async function () {
const stat = await fs.stat(cacheDir);
expect(stat.isDirectory()).toBeTruthy();
});
}
}
]
};

1 comment on commit 28f2169

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 28f2169 Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-12-30 437c370) Current Change
10000_big_production-mode_disable-minimize + exec 37.5 s ± 658 ms 37.8 s ± 480 ms +0.81 %
10000_development-mode + exec 1.89 s ± 22 ms 1.82 s ± 24 ms -3.89 %
10000_development-mode_hmr + exec 685 ms ± 15 ms 675 ms ± 3.9 ms -1.42 %
10000_production-mode + exec 2.49 s ± 46 ms 2.46 s ± 69 ms -1.26 %
arco-pro_development-mode + exec 1.75 s ± 76 ms 1.75 s ± 71 ms -0.07 %
arco-pro_development-mode_hmr + exec 378 ms ± 3.8 ms 377 ms ± 2.9 ms -0.16 %
arco-pro_production-mode + exec 3.64 s ± 75 ms 3.56 s ± 54 ms -2.24 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.64 s ± 76 ms 3.6 s ± 72 ms -1.35 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.63 s ± 80 ms 3.58 s ± 93 ms -1.44 %
threejs_development-mode_10x + exec 1.52 s ± 18 ms 1.5 s ± 23 ms -1.50 %
threejs_development-mode_10x_hmr + exec 790 ms ± 8.7 ms 760 ms ± 17 ms -3.86 %
threejs_production-mode_10x + exec 5.34 s ± 72 ms 5.34 s ± 65 ms -0.01 %
10000_big_production-mode_disable-minimize + rss memory 9458 MiB ± 133 MiB 9687 MiB ± 436 MiB +2.42 %
10000_development-mode + rss memory 650 MiB ± 8.03 MiB 702 MiB ± 25.1 MiB +7.93 %
10000_development-mode_hmr + rss memory 1421 MiB ± 196 MiB 1555 MiB ± 213 MiB +9.49 %
10000_production-mode + rss memory 618 MiB ± 21.6 MiB 679 MiB ± 22.8 MiB +9.89 %
arco-pro_development-mode + rss memory 592 MiB ± 24.8 MiB 588 MiB ± 35.8 MiB -0.77 %
arco-pro_development-mode_hmr + rss memory 636 MiB ± 47.2 MiB 629 MiB ± 37.4 MiB -1.09 %
arco-pro_production-mode + rss memory 725 MiB ± 44.8 MiB 735 MiB ± 61 MiB +1.35 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 770 MiB ± 58.4 MiB 751 MiB ± 46.1 MiB -2.47 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 750 MiB ± 36.5 MiB 746 MiB ± 33.9 MiB -0.54 %
threejs_development-mode_10x + rss memory 624 MiB ± 24 MiB 632 MiB ± 39.5 MiB +1.32 %
threejs_development-mode_10x_hmr + rss memory 1173 MiB ± 179 MiB 1179 MiB ± 62.7 MiB +0.53 %
threejs_production-mode_10x + rss memory 895 MiB ± 49.3 MiB 909 MiB ± 45.8 MiB +1.53 %

Please sign in to comment.