Skip to content

Commit 5372583

Browse files
committed
chore: add integration tests
1 parent 0afb621 commit 5372583

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function sleep(ms: number) {
2+
return new Promise(res => {
3+
setTimeout(() => {
4+
res(void 0);
5+
}, ms)
6+
});
7+
}
8+
9+
addEventListener("beforeunload", ev => {
10+
console.log(ev.detail);
11+
});
12+
13+
const mem = [];
14+
15+
export default {
16+
async fetch() {
17+
for (const _ of [...Array(12).keys()]) {
18+
const buf = new Uint8Array(1024 * 1024);
19+
buf.fill(1, 0);
20+
mem.push(buf);
21+
await sleep(300);
22+
}
23+
24+
return new Response();
25+
}
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function sleep(ms: number) {
2+
return new Promise(res => {
3+
setTimeout(() => {
4+
res(void 0);
5+
}, ms)
6+
});
7+
}
8+
9+
addEventListener("beforeunload", ev => {
10+
console.log(ev.detail);
11+
});
12+
13+
export default {
14+
async fetch() {
15+
await sleep(2000);
16+
return new Response();
17+
}
18+
}

crates/base/tests/integration_tests.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,6 +3295,88 @@ async fn test_should_not_wait_for_background_tests() {
32953295
}
32963296
}
32973297

3298+
#[tokio::test]
3299+
#[serial]
3300+
async fn test_should_be_able_to_trigger_early_drop_with_wall_clock() {
3301+
let (tx, mut rx) = mpsc::unbounded_channel();
3302+
let tb = TestBedBuilder::new("./test_cases/main")
3303+
.with_per_worker_policy(None)
3304+
.with_worker_event_sender(Some(tx))
3305+
.build()
3306+
.await;
3307+
3308+
let resp = tb
3309+
.request(|b| {
3310+
b.uri("/early-drop-wall-clock")
3311+
.header("x-worker-timeout-ms", HeaderValue::from_static("3000"))
3312+
.body(Body::empty())
3313+
.context("can't make request")
3314+
})
3315+
.await
3316+
.unwrap();
3317+
3318+
assert_eq!(resp.status().as_u16(), StatusCode::OK);
3319+
3320+
sleep(Duration::from_secs(2)).await;
3321+
rx.close();
3322+
tb.exit(Duration::from_secs(TESTBED_DEADLINE_SEC)).await;
3323+
3324+
while let Some(ev) = rx.recv().await {
3325+
let WorkerEvents::Log(ev) = ev.event else {
3326+
continue;
3327+
};
3328+
if ev.level != LogLevel::Info {
3329+
continue;
3330+
}
3331+
if ev.msg.contains("early_drop") {
3332+
return;
3333+
}
3334+
}
3335+
3336+
unreachable!("test failed");
3337+
}
3338+
3339+
#[tokio::test]
3340+
#[serial]
3341+
async fn test_should_be_able_to_trigger_early_drop_with_mem() {
3342+
let (tx, mut rx) = mpsc::unbounded_channel();
3343+
let tb = TestBedBuilder::new("./test_cases/main")
3344+
.with_per_worker_policy(None)
3345+
.with_worker_event_sender(Some(tx))
3346+
.build()
3347+
.await;
3348+
3349+
let resp = tb
3350+
.request(|b| {
3351+
b.uri("/early-drop-mem")
3352+
.header("x-memory-limit-mb", HeaderValue::from_static("20"))
3353+
.body(Body::empty())
3354+
.context("can't make request")
3355+
})
3356+
.await
3357+
.unwrap();
3358+
3359+
assert_eq!(resp.status().as_u16(), StatusCode::OK);
3360+
3361+
sleep(Duration::from_secs(2)).await;
3362+
rx.close();
3363+
tb.exit(Duration::from_secs(TESTBED_DEADLINE_SEC)).await;
3364+
3365+
while let Some(ev) = rx.recv().await {
3366+
let WorkerEvents::Log(ev) = ev.event else {
3367+
continue;
3368+
};
3369+
if ev.level != LogLevel::Info {
3370+
continue;
3371+
}
3372+
if ev.msg.contains("early_drop") {
3373+
return;
3374+
}
3375+
}
3376+
3377+
unreachable!("test failed");
3378+
}
3379+
32983380
#[derive(Deserialize)]
32993381
struct ErrorResponsePayload {
33003382
msg: String,

0 commit comments

Comments
 (0)