-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into recorder-work
- Loading branch information
Showing
15 changed files
with
441 additions
and
203 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pywb>=2.7.4 | ||
uwsgi | ||
wacz>=0.4.8 | ||
wacz>=0.4.9 | ||
requests[socks] |
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,3 @@ | ||
import { jest } from "@jest/globals"; | ||
|
||
global.jest = jest; |
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,23 @@ | ||
import child_process from "child_process"; | ||
|
||
test("test custom behaviors", async () => { | ||
const res = child_process.execSync("docker run -v $PWD/test-crawls:/crawls -v $PWD/tests/custom-behaviors/:/custom-behaviors/ webrecorder/browsertrix-crawler crawl --url https://example.com/ --url https://example.org/ --url https://webrecorder.net/ --customBehaviors /custom-behaviors/ --scopeType page"); | ||
|
||
const log = res.toString(); | ||
|
||
// custom behavior ran for example.com | ||
expect(log.indexOf("{\"state\":{},\"msg\":\"test-stat\",\"page\":\"https://example.com/\",\"workerid\":0}}") > 0).toBe(true); | ||
|
||
// but not for example.org | ||
expect(log.indexOf("{\"state\":{},\"msg\":\"test-stat\",\"page\":\"https://example.org/\",\"workerid\":0}}") > 0).toBe(false); | ||
|
||
expect(log.indexOf("{\"state\":{\"segments\":1},\"msg\":\"Skipping autoscroll, page seems to not be responsive to scrolling events\",\"page\":\"https://example.org/\",\"workerid\":0}}") > 0).toBe(true); | ||
|
||
// another custom behavior ran for webrecorder.net | ||
expect(log.indexOf("{\"state\":{},\"msg\":\"test-stat-2\",\"page\":\"https://webrecorder.net/\",\"workerid\":0}}") > 0).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class TestBehavior2 | ||
{ | ||
static init() { | ||
return { | ||
state: {} | ||
}; | ||
} | ||
|
||
static get id() { | ||
return "TestBehavior2"; | ||
} | ||
|
||
static isMatch() { | ||
return window.location.origin === "https://webrecorder.net"; | ||
} | ||
|
||
|
||
async* run(ctx) { | ||
ctx.log("In Test Behavior 2!"); | ||
yield ctx.Lib.getState(ctx, "test-stat-2"); | ||
} | ||
} |
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,22 @@ | ||
class TestBehavior | ||
{ | ||
static init() { | ||
return { | ||
state: {} | ||
}; | ||
} | ||
|
||
static get id() { | ||
return "TestBehavior"; | ||
} | ||
|
||
static isMatch() { | ||
return window.location.origin === "https://example.com"; | ||
} | ||
|
||
|
||
async* run(ctx) { | ||
ctx.log("In Test Behavior!"); | ||
yield ctx.Lib.getState(ctx, "test-stat"); | ||
} | ||
} |
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,62 @@ | ||
import { calculatePercentageUsed, checkDiskUtilization } from "../util/storage.js"; | ||
|
||
|
||
test("ensure calculatePercentageUsed returns expected values", () => { | ||
expect(calculatePercentageUsed(30, 100)).toEqual(30); | ||
|
||
expect(calculatePercentageUsed(1507, 35750)).toEqual(4); | ||
|
||
expect(calculatePercentageUsed(33819, 35750)).toEqual(95); | ||
|
||
expect(calculatePercentageUsed(140, 70)).toEqual(200); | ||
|
||
expect(calculatePercentageUsed(0, 5)).toEqual(0); | ||
}); | ||
|
||
|
||
test("verify end-to-end disk utilization not exceeded threshold", async () => { | ||
|
||
const params = { | ||
diskUtilization: 90, | ||
combineWARC: true, | ||
generateWACZ: true | ||
}; | ||
|
||
const mockDfOutput = `\ | ||
Filesystem 1K-blocks Used Available Use% Mounted on | ||
grpcfuse 1000000 285000 715000 28% /crawls`; | ||
|
||
// with combineWARC + generateWACZ, projected is 285k + 4 * 5k = 310k = 31% | ||
// does not exceed 90% threshold | ||
const returnValue = await checkDiskUtilization(params, 5000 * 1024, mockDfOutput); | ||
expect(returnValue).toEqual({ | ||
stop: false, | ||
used: 28, | ||
projected: 31, | ||
threshold: 90 | ||
}); | ||
}); | ||
|
||
|
||
test("verify end-to-end disk utilization exceeds threshold", async () => { | ||
|
||
const params = { | ||
diskUtilization: 90, | ||
combineWARC: false, | ||
generateWACZ: true | ||
}; | ||
|
||
const mockDfOutput = `\ | ||
Filesystem 1K-blocks Used Available Use% Mounted on | ||
grpcfuse 100000 85000 15000 85% /crawls`; | ||
|
||
// with generateWACZ, projected is 85k + 3k x 2 = 91k = 91% | ||
// exceeds 90% threshold | ||
const returnValue = await checkDiskUtilization(params, 3000 * 1024, mockDfOutput); | ||
expect(returnValue).toEqual({ | ||
stop: true, | ||
used: 85, | ||
projected: 91, | ||
threshold: 90 | ||
}); | ||
}); |
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,33 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const MAX_DEPTH = 2; | ||
|
||
export function collectAllFileSources(fileOrDir, ext = null, depth = 0) { | ||
const resolvedPath = path.resolve(fileOrDir); | ||
|
||
if (depth >= MAX_DEPTH) { | ||
console.warn(`WARN: MAX_DEPTH of ${MAX_DEPTH} reached traversing "${resolvedPath}"`); | ||
return []; | ||
} | ||
|
||
const stat = fs.statSync(resolvedPath); | ||
|
||
if (stat.isFile && (ext === null || path.extname(resolvedPath) === ext)) { | ||
const contents = fs.readFileSync(resolvedPath); | ||
return [`/* src: ${resolvedPath} */\n\n${contents}`]; | ||
} | ||
|
||
if (stat.isDirectory) { | ||
const files = fs.readdirSync(resolvedPath); | ||
return files.reduce((acc, next) => { | ||
const nextPath = path.join(fileOrDir, next); | ||
return [...acc, ...collectAllFileSources(nextPath, ext, depth + 1)]; | ||
}, []); | ||
} | ||
|
||
if (depth === 0) { | ||
console.warn(`WARN: The provided path "${resolvedPath}" is not a .js file or directory.`); | ||
return []; | ||
} | ||
} |
Oops, something went wrong.