Skip to content

Commit 6387ccc

Browse files
committed
refactor: wip
1 parent 6d9d5c1 commit 6387ccc

8 files changed

Lines changed: 109 additions & 644 deletions

File tree

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
1-
import {
2-
WAL_ID_PATTERNS,
3-
getUniqueReadableInstanceId,
4-
getUniqueRunId,
5-
} from './process-id.js';
1+
import { WAL_ID_PATTERNS, getUniqueTimeId } from './process-id.js';
2+
import { getShardId } from './wal-sharded.js';
63

7-
describe('getUniqueReadableInstanceId', () => {
4+
describe('getShardId (formerly getUniqueReadableInstanceId)', () => {
85
it('should generate shard ID with readable timestamp', () => {
9-
const result = getUniqueReadableInstanceId();
6+
const result = getShardId();
107

118
expect(result).toMatch(WAL_ID_PATTERNS.INSTANCE_ID);
129
expect(result).toStartWith('20231114-221320-000.');
1310
});
1411

1512
it('should generate different shard IDs for different calls', () => {
16-
const result1 = getUniqueReadableInstanceId();
17-
const result2 = getUniqueReadableInstanceId();
13+
const result1 = getShardId();
14+
const result2 = getShardId();
1815

1916
expect(result1).not.toBe(result2);
2017
expect(result1).toStartWith('20231114-221320-000.');
2118
expect(result2).toStartWith('20231114-221320-000.');
2219
});
2320

2421
it('should handle zero values', () => {
25-
const result = getUniqueReadableInstanceId();
22+
const result = getShardId();
2623
expect(result).toStartWith('20231114-221320-000.');
2724
});
2825

2926
it('should handle negative timestamps', () => {
30-
const result = getUniqueReadableInstanceId();
27+
const result = getShardId();
3128

3229
expect(result).toStartWith('20231114-221320-000.');
3330
});
3431

3532
it('should handle large timestamps', () => {
36-
const result = getUniqueReadableInstanceId();
33+
const result = getShardId();
3734

3835
expect(result).toStartWith('20231114-221320-000.');
3936
});
4037

4138
it('should generate incrementing counter', () => {
42-
const result1 = getUniqueReadableInstanceId();
43-
const result2 = getUniqueReadableInstanceId();
39+
const result1 = getShardId();
40+
const result2 = getShardId();
4441

4542
const parts1 = result1.split('.');
4643
const parts2 = result2.split('.');
@@ -53,18 +50,22 @@ describe('getUniqueReadableInstanceId', () => {
5350
});
5451
});
5552

56-
describe('getUniqueRunId', () => {
53+
describe('getUniqueTimeId (formerly getUniqueRunId)', () => {
5754
it('should work with mocked timeOrigin', () => {
58-
const result = getUniqueRunId();
55+
const result = getUniqueTimeId();
5956

6057
expect(result).toBe('20231114-221320-000');
6158
expect(result).toMatch(WAL_ID_PATTERNS.GROUP_ID);
6259
});
6360

64-
it('should be idempotent within same process', () => {
65-
const result1 = getUniqueRunId();
66-
const result2 = getUniqueRunId();
61+
it('should generate new ID on each call (not idempotent)', () => {
62+
const result1 = getUniqueTimeId();
63+
const result2 = getUniqueTimeId();
6764

68-
expect(result1).toBe(result2);
65+
// Note: getUniqueTimeId is not idempotent - it generates a new ID each call
66+
// based on current time, so results will be different
67+
expect(result1).toMatch(WAL_ID_PATTERNS.GROUP_ID);
68+
expect(result2).toMatch(WAL_ID_PATTERNS.GROUP_ID);
69+
// They may be the same if called within the same millisecond, but generally different
6970
});
7071
});
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{"cat":"blink.user_timing","ph":"i","name":"write-test:test-operation:start","pid":10001,"tid":1,"ts":1700000005000000,"args":{"detail":"{\"devtools\":{\"track\":\"Test\",\"dataType\":\"track-entry\"}}"}}
2-
{"cat":"blink.user_timing","ph":"b","name":"write-test:test-operation","id2":{"local":"0x1"},"pid":10001,"tid":1,"ts":1700000005000001,"args":{"data":{"detail":"{\"devtools\":{\"track\":\"Test\",\"dataType\":\"track-entry\"}}"}}}
3-
{"cat":"blink.user_timing","ph":"e","name":"write-test:test-operation","id2":{"local":"0x1"},"pid":10001,"tid":1,"ts":1700000005000002,"args":{"data":{"detail":"{\"devtools\":{\"track\":\"Test\",\"dataType\":\"track-entry\"}}"}}}
4-
{"cat":"blink.user_timing","ph":"i","name":"write-test:test-operation:end","pid":10001,"tid":1,"ts":1700000005000003,"args":{"detail":"{\"devtools\":{\"track\":\"Test\",\"dataType\":\"track-entry\"}}"}}
1+
{"cat":"blink.user_timing","ph":"i","name":"write-test:test-operation:start","pid":10001,"tid":1,"ts":1700000005000000,"args":{"detail":{"devtools":{"track":"Test","dataType":"track-entry"}}}}
2+
{"cat":"blink.user_timing","ph":"b","name":"write-test:test-operation","id2":{"local":"0x1"},"pid":10001,"tid":1,"ts":1700000005000001,"args":{"data":{"detail":{"devtools":{"track":"Test","dataType":"track-entry"}}}}}
3+
{"cat":"blink.user_timing","ph":"e","name":"write-test:test-operation","id2":{"local":"0x1"},"pid":10001,"tid":1,"ts":1700000005000002,"args":{"data":{"detail":{"devtools":{"track":"Test","dataType":"track-entry"}}}}}
4+
{"cat":"blink.user_timing","ph":"i","name":"write-test:test-operation:end","pid":10001,"tid":1,"ts":1700000005000003,"args":{"detail":{"devtools":{"track":"Test","dataType":"track-entry"}}}}

packages/utils/src/lib/profiler/folder.int.test.ts

Lines changed: 0 additions & 299 deletions
This file was deleted.

0 commit comments

Comments
 (0)