Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions src/workerd/server/alarm-scheduler.c++
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,6 @@ bool AlarmScheduler::deleteAlarm(ActorKey actor) {
return query.changeCount() > 0;
}

void AlarmScheduler::deleteAllAlarms() {
stmtDeleteAllAlarms.run();

alarms.eraseAll([this](ActorKey& key, ScheduledAlarm& value) {
KJ_IF_SOME(queued, value.queuedAlarm) {
if (value.status == AlarmStatus::STARTED) {
// If we are currently running an alarm, we want to delete the queued instead of current.
value.queuedAlarm = kj::none;
} else {
alarms.upsert(key, scheduleAlarm(clock.now(), kj::mv(value.actor), queued));
}
return false;
} else {
// We can't remove running alarms.
return value.status != AlarmStatus::STARTED;
}
});
}

kj::Promise<AlarmScheduler::RetryInfo> AlarmScheduler::runAlarm(
const ActorKey& actor, kj::Date scheduledTime, uint32_t retryCount) {
KJ_IF_SOME(ns, namespaces.find(actor.uniqueKey)) {
Expand Down
4 changes: 0 additions & 4 deletions src/workerd/server/alarm-scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class AlarmScheduler final: kj::TaskSet::ErrorHandler {
kj::Maybe<kj::Date> getAlarm(ActorKey actor);
bool setAlarm(ActorKey actor, kj::Date scheduledTime);
bool deleteAlarm(ActorKey actor);
void deleteAllAlarms();

void registerNamespace(kj::StringPtr uniqueKey, GetActorFn getActor);

Expand Down Expand Up @@ -129,9 +128,6 @@ class AlarmScheduler final: kj::TaskSet::ErrorHandler {
SqliteDatabase::Statement stmtDeleteAlarm = db->prepare(R"(
DELETE FROM _cf_ALARM WHERE actor_unique_key = ? AND actor_id = ?
)");
SqliteDatabase::Statement stmtDeleteAllAlarms = db->prepare(R"(
DELETE FROM _cf_ALARM
)");

void taskFailed(kj::Exception&& exception) override;

Expand Down
7 changes: 0 additions & 7 deletions src/workerd/server/server.c++
Original file line number Diff line number Diff line change
Expand Up @@ -3985,13 +3985,6 @@ void Server::abortAllActors(kj::Maybe<const kj::Exception&> reason) {
}
}
}

// When using vitest-pool-workers and DOs have alarms, alarms can still attempt to run after the tests
// end running that leads to internal reference errors.
// On more complex setups with multiple DOs that have alarms and all of them communicate with one another,
// there might be cases where there are isolated storage errors when calling DOs wake one another.
// Deleting all of them at the same time guarantees that user's implementations don't affect tests runs
alarmScheduler->deleteAllAlarms();
}

// WorkerDef is an intermediate representation of everything from `config::Worker::Reader` that
Expand Down
35 changes: 0 additions & 35 deletions src/workerd/server/tests/unsafe-module/unsafe-module-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from 'node:assert';
import unsafe from 'workerd:unsafe';
import { DurableObject } from 'cloudflare:workers';

function createTestObject(type) {
return class {
Expand All @@ -19,19 +18,6 @@ export const TestEphemeralObjectPreventEviction = createTestObject(
'ephemeral-prevent-eviction'
);

let alarmTriggers = 0;
export class AlarmObject extends DurableObject {
get scheduledTime() {
return this.ctx.storage.getAlarm();
}
async scheduleIn(delay) {
await this.ctx.storage.setAlarm(Date.now() + delay);
}
alarm() {
alarmTriggers++;
}
}

export const test_abort_all_durable_objects = {
async test(ctrl, env, ctx) {
const durableId = env.DURABLE.newUniqueId();
Expand Down Expand Up @@ -99,24 +85,3 @@ export const test_abort_all_durable_objects = {
);
},
};

export const test_abort_all_durable_objects_alarms = {
async test(ctrl, env, ctx) {
const id = env.ALARM.newUniqueId();
const stub = env.ALARM.get(id);

// Check we can schedule an alarm as usual
assert.strictEqual(await stub.scheduledTime, null);
await stub.scheduleIn(500);
assert.notStrictEqual(await stub.scheduledTime, null);
await scheduler.wait(1000);
assert.strictEqual(alarmTriggers, 1);
assert.strictEqual(await stub.scheduledTime, null);

// Check `abortAllDurableObjects()` deletes all alarms
await stub.scheduleIn(500);
await unsafe.abortAllDurableObjects();
await scheduler.wait(1000);
assert.strictEqual(alarmTriggers, 1); // (same as before)
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@ using Workerd = import "/workerd/workerd.capnp";

const unitTests :Workerd.Config = (
services = [
( name = "TEST_TMPDIR", disk = (writable = true) ),
( name = "unsafe-module-test",
worker = (
modules = [
( name = "worker", esModule = embed "unsafe-module-test.js" ),
],
compatibilityFlags = ["nodejs_compat", "unsafe_module", "rpc"],
compatibilityFlags = ["nodejs_compat", "unsafe_module"],
durableObjectNamespaces = [
( className = "TestDurableObject", uniqueKey = "durable" ),
( className = "TestDurableObjectPreventEviction", uniqueKey = "durable-prevent-eviction", preventEviction = true ),
( className = "TestEphemeralObject", ephemeralLocal = void ),
( className = "TestEphemeralObjectPreventEviction", ephemeralLocal = void, preventEviction = true ),
( className = "AlarmObject", uniqueKey = "alarm" ),
],
durableObjectStorage = ( localDisk = "TEST_TMPDIR" ),
durableObjectStorage = (inMemory = void),
bindings = [
( name = "DURABLE", durableObjectNamespace = "TestDurableObject" ),
( name = "DURABLE_PREVENT_EVICTION", durableObjectNamespace = "TestDurableObjectPreventEviction" ),
( name = "EPHEMERAL", durableObjectNamespace = "TestEphemeralObject" ),
( name = "EPHEMERAL_PREVENT_EVICTION", durableObjectNamespace = "TestEphemeralObjectPreventEviction" ),
( name = "ALARM", durableObjectNamespace = "AlarmObject" ),
],
)
),
Expand Down
Loading