@@ -20,6 +20,7 @@ import { VuidManager } from '../lib/plugins/vuid_manager';
20
20
import PersistentKeyValueCache from '../lib/plugins/key_value_cache/persistentKeyValueCache' ;
21
21
import { anyString , anything , instance , mock , resetCalls , verify , when } from 'ts-mockito' ;
22
22
import { LogHandler } from '../lib/modules/logging/models' ;
23
+ import { resolvablePromise } from '../lib/utils/promise/resolvablePromise' ;
23
24
24
25
describe ( 'VuidManager' , ( ) => {
25
26
let mockCache : PersistentKeyValueCache < string > ;
@@ -93,4 +94,31 @@ describe('VuidManager', () => {
93
94
verify ( mockCache . remove ( anyString ( ) ) ) . once ( ) ;
94
95
expect ( manager . vuid ) . toBeUndefined ( ) ;
95
96
} ) ;
97
+
98
+ it ( 'should sequence configure calls' , async ( ) => {
99
+ const mockCache = mock < PersistentKeyValueCache > ( ) ;
100
+ when ( mockCache . contains ( anyString ( ) ) ) . thenResolve ( true ) ;
101
+ when ( mockCache . get ( anyString ( ) ) ) . thenResolve ( '' ) ;
102
+
103
+ const removePromise = resolvablePromise < boolean > ( ) ;
104
+ when ( mockCache . remove ( anyString ( ) ) ) . thenReturn ( removePromise . promise ) ;
105
+ when ( mockCache . set ( anyString ( ) , anything ( ) ) ) . thenResolve ( ) ;
106
+
107
+ const manager = new VuidManager ( instance ( mockCache ) ) ;
108
+
109
+ // this should try to remove vuid, which should stay pending
110
+ manager . configure ( { enableVuid : false } ) ;
111
+
112
+ // this should try to get the vuid from store
113
+ manager . configure ( { enableVuid : true } ) ;
114
+ verify ( mockCache . get ( anyString ( ) ) ) . never ( ) ;
115
+
116
+ removePromise . resolve ( true ) ;
117
+ //ensure micro task queue is exhaused
118
+ for ( let i = 0 ; i < 100 ; i ++ ) {
119
+ await Promise . resolve ( ) ;
120
+ }
121
+
122
+ verify ( mockCache . get ( anyString ( ) ) ) . once ( )
123
+ } ) ;
96
124
} ) ;
0 commit comments