@agoric/telemetry 0.6.3-other-dev-8f8782b.0 → 0.6.3-other-dev-fbe72e7.0.fbe72e7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,114 @@
1
+ import fs from 'node:fs';
2
+ import tmp from 'tmp';
3
+ import { test } from './prepare-test-env-ava.js';
4
+
5
+ import {
6
+ makeSimpleCircularBuffer,
7
+ makeSlogSenderFromBuffer,
8
+ } from '../src/flight-recorder.js';
9
+
10
+ // Factored this way to support multiple implementations, which at one point there were
11
+ const bufferTests = test.macro(
12
+ /**
13
+ *
14
+ * @param {*} t
15
+ * @param {{makeBuffer: typeof makeSimpleCircularBuffer}} input
16
+ */
17
+ async (t, input) => {
18
+ const BUFFER_SIZE = 512;
19
+
20
+ const { name: tmpFile, removeCallback } = tmp.fileSync({
21
+ discardDescriptor: true,
22
+ });
23
+ t.teardown(removeCallback);
24
+ const { fileHandle, readCircBuf, writeCircBuf } = await input.makeBuffer({
25
+ circularBufferSize: BUFFER_SIZE,
26
+ circularBufferFilename: tmpFile,
27
+ });
28
+ const realSlogSender = makeSlogSenderFromBuffer({
29
+ fileHandle,
30
+ writeCircBuf,
31
+ });
32
+ let wasShutdown = false;
33
+ const shutdown = () => {
34
+ if (wasShutdown) return;
35
+ wasShutdown = true;
36
+
37
+ return realSlogSender.shutdown();
38
+ };
39
+ t.teardown(shutdown);
40
+ // To verify lack of attempted mutation by the consumer, send only hardened
41
+ // entries.
42
+ /** @type {typeof realSlogSender} */
43
+ const slogSender = Object.assign(
44
+ (obj, serialized) => realSlogSender(harden(obj), serialized),
45
+ realSlogSender,
46
+ );
47
+ slogSender({ type: 'start' });
48
+ await slogSender.forceFlush();
49
+ t.is(fs.readFileSync(tmpFile, { encoding: 'utf8' }).length, BUFFER_SIZE);
50
+
51
+ const len0 = new Uint8Array(BigUint64Array.BYTES_PER_ELEMENT);
52
+ const { done: done0 } = await readCircBuf(len0);
53
+ t.false(done0, 'readCircBuf should not be done');
54
+ const dv0 = new DataView(len0.buffer);
55
+ const buf0 = new Uint8Array(Number(dv0.getBigUint64(0)));
56
+ const { done: done0b } = await readCircBuf(buf0, len0.byteLength);
57
+ t.false(done0b, 'readCircBuf should not be done');
58
+ const buf0Str = new TextDecoder().decode(buf0);
59
+ t.is(buf0Str, `\n{"type":"start"}`, `start compare failed`);
60
+
61
+ const last = 500;
62
+ for (let i = 0; i < last; i += 1) {
63
+ slogSender({ type: 'iteration', iteration: i });
64
+ await slogSender.forceFlush();
65
+ t.is(
66
+ fs.readFileSync(tmpFile, { encoding: 'utf8' }).length,
67
+ BUFFER_SIZE,
68
+ `iteration ${i} length mismatch`,
69
+ );
70
+ }
71
+
72
+ let offset = 0;
73
+ const len1 = new Uint8Array(BigUint64Array.BYTES_PER_ELEMENT);
74
+ for (let i = 490; i < last; i += 1) {
75
+ const { done: done1 } = await readCircBuf(len1, offset);
76
+ offset += len1.byteLength;
77
+ t.false(done1, `readCircBuf ${i} should not be done`);
78
+ const dv1 = new DataView(len1.buffer);
79
+ const buf1 = new Uint8Array(Number(dv1.getBigUint64(0)));
80
+ const { done: done1b } = await readCircBuf(buf1, offset);
81
+ offset += buf1.byteLength;
82
+ t.false(done1b, `readCircBuf ${i} should not be done`);
83
+ const buf1Str = new TextDecoder().decode(buf1);
84
+ t.is(
85
+ buf1Str,
86
+ `\n{"type":"iteration","iteration":${i}}`,
87
+ `iteration ${i} compare failed`,
88
+ );
89
+ }
90
+
91
+ const { done: done2 } = await readCircBuf(len1, offset);
92
+ t.assert(done2, `readCircBuf ${last} should be done`);
93
+
94
+ slogSender(null, 'PRE-SERIALIZED');
95
+ await slogSender.forceFlush();
96
+ t.truthy(fs.readFileSync(tmpFile).includes('PRE-SERIALIZED'));
97
+
98
+ slogSender(null, 'PRE_SHUTDOWN');
99
+ const shutdownP = shutdown();
100
+ slogSender(null, 'POST_SHUTDOWN');
101
+ await shutdownP;
102
+ slogSender(null, 'SHUTDOWN_COMPLETED');
103
+
104
+ const finalContent = fs.readFileSync(tmpFile);
105
+
106
+ t.truthy(finalContent.includes('PRE_SHUTDOWN'));
107
+ t.falsy(finalContent.includes('POST_SHUTDOWN'));
108
+ t.falsy(finalContent.includes('SHUTDOWN_COMPLETED'));
109
+ },
110
+ );
111
+
112
+ test('simple', bufferTests, {
113
+ makeBuffer: makeSimpleCircularBuffer,
114
+ });
@@ -1,5 +1,3 @@
1
- import '@endo/init';
2
-
3
1
  import { wrapTest } from '@endo/ses-ava';
4
2
  import rawTest from 'ava';
5
3
 
@@ -1,6 +1,7 @@
1
1
  // This file can contain .js-specific Typescript compiler config.
2
2
  {
3
3
  "extends": "../../tsconfig.json",
4
+ "compilerOptions": {},
4
5
  "include": [
5
6
  "*.js",
6
7
  "scripts",
@@ -1,53 +0,0 @@
1
- import tmp from 'tmp';
2
- import { test } from './prepare-test-env-ava.js';
3
-
4
- import { makeMemoryMappedCircularBuffer } from '../src/flight-recorder.js';
5
-
6
- test('flight-recorder sanity', async t => {
7
- const { name: tmpFile, removeCallback } = tmp.fileSync();
8
- const { writeJSON: slogSender, readCircBuf } =
9
- await makeMemoryMappedCircularBuffer({
10
- circularBufferSize: 512,
11
- circularBufferFilename: tmpFile,
12
- });
13
- slogSender({ type: 'start' });
14
-
15
- const len0 = new Uint8Array(BigUint64Array.BYTES_PER_ELEMENT);
16
- const { done: done0 } = readCircBuf(len0);
17
- t.false(done0, 'readCircBuf should not be done');
18
- const dv0 = new DataView(len0.buffer);
19
- const buf0 = new Uint8Array(Number(dv0.getBigUint64(0)));
20
- const { done: done0b } = readCircBuf(buf0, len0.byteLength);
21
- t.false(done0b, 'readCircBuf should not be done');
22
- const buf0Str = new TextDecoder().decode(buf0);
23
- t.is(buf0Str, `\n{"type":"start"}`, `start compare failed`);
24
-
25
- const last = 500;
26
- for (let i = 0; i < last; i += 1) {
27
- slogSender({ type: 'iteration', iteration: i });
28
- }
29
-
30
- let offset = 0;
31
- const len1 = new Uint8Array(BigUint64Array.BYTES_PER_ELEMENT);
32
- for (let i = 490; i < last; i += 1) {
33
- const { done: done1 } = readCircBuf(len1, offset);
34
- offset += len1.byteLength;
35
- t.false(done1, `readCircBuf ${i} should not be done`);
36
- const dv1 = new DataView(len1.buffer);
37
- const buf1 = new Uint8Array(Number(dv1.getBigUint64(0)));
38
- const { done: done1b } = readCircBuf(buf1, offset);
39
- offset += buf1.byteLength;
40
- t.false(done1b, `readCircBuf ${i} should not be done`);
41
- const buf1Str = new TextDecoder().decode(buf1);
42
- t.is(
43
- buf1Str,
44
- `\n{"type":"iteration","iteration":${i}}`,
45
- `iteration ${i} compare failed`,
46
- );
47
- }
48
-
49
- const { done: done2 } = readCircBuf(len1, offset);
50
- t.assert(done2, `readCircBuf ${last} should be done`);
51
- // console.log({ tmpFile });
52
- removeCallback();
53
- });
File without changes