File
Blob: src/workerd/api/tests/analytics-engine-test.js
| 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 |
| 4 | import * as assert from 'node:assert'; |
| 5 | |
| 6 | let written = false; |
| 7 | async 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 | |
| 16 | export 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 | }; |