From 606197c98ff03324c90652d2fab6e3dbd9b9991a Mon Sep 17 00:00:00 2001
From: Gregory Baker
Date: Tue, 31 Jan 2023 12:33:08 -0700
Subject: [PATCH 1/3] try to fetch timestamp from worker using service binding
---
src/index.html | 15 ++++++++++++++-
src/index.ts | 24 ++++++++++++++++++------
wrangler.toml | 6 +++++-
3 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/src/index.html b/src/index.html
index 304a3f2..e1eb860 100644
--- a/src/index.html
+++ b/src/index.html
@@ -16,7 +16,7 @@
CF Worker and DO Clocks Tests
This page logs information about the delta between its clock and the
clock of a Cloudflare worker or durable-object as observed over a
- series of requests. It has three test cases.
+ series of requests. It has four test cases.
In each test case the page sends its current time as reported by
Date.now() every 250ms to a worker (which depending on the test case
may forward it to a durable-object). The worker or durable-object
@@ -42,6 +42,11 @@
CF Worker and DO Clocks Tests
is responded to by the durable-object via a Websocket message with
the durable-object's time.
+
+ do-worker-post: time is sent via a POST request which is responded
+ to by the durable-object with a timestamp it fetches from the worker
+ over a service binding. The work computation is done on the do.
+
to by the durable-object with a timestamp it fetches from the worker
over a service binding. The work computation is done on the do.
+
+ do-worker-internet-post: time is sent via a POST request which is responded
+ to by the durable-object with a timestamp it fetches from the worker
+ by url using internet routing. The work computation is done on the do.
+
@@ -84,7 +89,14 @@
CF Worker and DO Clocks Tests
name="test"
value="do-worker-post"
/>
-
+
+
+
Select work per request/message:
@@ -208,6 +220,7 @@
Log (new messages are prepended)
case "worker-post":
case "do-post":
case "do-worker-post":
+ case "do-worker-internet-post":
testPost();
break;
case "do-websocket":
diff --git a/src/index.ts b/src/index.ts
index bfa8702..be94c10 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -36,6 +36,7 @@ const worker = {
return handlePost(request, workerID, Date.now(), ctx);
case "/do-post":
case "/do-worker-post":
+ case "/do-worker-internet-post":
case "/do-websocket":
return forward();
}
@@ -56,11 +57,23 @@ class ClocksTestDO implements DurableObject {
console.log(this._doID, "DO clockWorker", this._env.clockWorker);
const url = new URL(request.url);
switch (url.pathname) {
- case "/do-worker-post":
+ case "/do-worker-post": {
const { id, now } = await (
await this._env.clockWorker.fetch("https://unused/now")
).json<{ id: string; now: number }>();
return handlePost(request, this._doID + "/" + id, now);
+ }
+ case "/do-worker-internet-post": {
+ const response = await fetch(
+ "https://cf-worker-clocks-test-w-service-bindings.replicache.workers.dev/now"
+ );
+ console.log(response.status, response.statusText);
+ if (response.status !== 200) {
+ return new Response(response.statusText, response);
+ }
+ const { id, now } = await response.json<{ id: string; now: number }>();
+ return handlePost(request, this._doID + "/" + id, now);
+ }
case "/do-post":
return handlePost(request, this._doID, Date.now());
case "/do-websocket":
From 529ce1377c70f91b71fbe8073227ca067475d463 Mon Sep 17 00:00:00 2001
From: Gregory Baker
Date: Tue, 31 Jan 2023 16:52:45 -0700
Subject: [PATCH 3/3] fix text
---
src/index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/index.html b/src/index.html
index 48a241c..a7fe9a6 100644
--- a/src/index.html
+++ b/src/index.html
@@ -16,7 +16,7 @@
CF Worker and DO Clocks Tests
This page logs information about the delta between its clock and the
clock of a Cloudflare worker or durable-object as observed over a
- series of requests. It has four test cases.
+ series of requests. It has several test cases.
In each test case the page sends its current time as reported by
Date.now() every 250ms to a worker (which depending on the test case
may forward it to a durable-object). The worker or durable-object