Skip to content
File

Blob: src/workerd/api/tests/analytics-engine-test.js

javascript31 lines
1// Copyright (c) 2023 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4import * as assert from 'node:assert';
5 
6let written = false;
7async function isWritten(timeout) {
8 const start = Date.now();
9 do {
10 if (written) return true;
11 await scheduler.wait(100);
12 } while (Date.now() - start < timeout);
13 throw new Error('Test never received request from analytics engine handler');
14}
15 
16export default {
17 async fetch(ctrl, env, ctx) {
18 written = true;
19 return new Response('');
20 },
21 async test(ctrl, env, ctx) {
22 env.aebinding.writeDataPoint({
23 blobs: ['TestBlob'],
24 doubles: [25],
25 indexes: ['testindex'],
26 });
27 
28 assert.equal(await isWritten(5000), true);
29 },
30};