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} ) ;
0 commit comments