File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,37 @@ describe('domains', () => {
38
38
} ) ;
39
39
} ) ;
40
40
41
+ test ( 'async hub scope inheritance' , async ( ) => {
42
+ setDomainAsyncContextStrategy ( ) ;
43
+
44
+ async function addRandomExtra ( hub : Hub , key : string ) : Promise < void > {
45
+ return new Promise ( resolve => {
46
+ setTimeout ( ( ) => {
47
+ hub . setExtra ( key , Math . random ( ) ) ;
48
+ resolve ( ) ;
49
+ } , 100 ) ;
50
+ } ) ;
51
+ }
52
+
53
+ const globalHub = getCurrentHub ( ) ;
54
+ await addRandomExtra ( globalHub , 'a' ) ;
55
+
56
+ await runWithAsyncContext ( async hub1 => {
57
+ expect ( hub1 ) . toEqual ( globalHub ) ;
58
+
59
+ await addRandomExtra ( hub1 , 'b' ) ;
60
+ expect ( hub1 ) . not . toEqual ( globalHub ) ;
61
+
62
+ await runWithAsyncContext ( async hub2 => {
63
+ expect ( hub2 ) . toEqual ( hub1 ) ;
64
+ expect ( hub2 ) . not . toEqual ( globalHub ) ;
65
+
66
+ await addRandomExtra ( hub1 , 'c' ) ;
67
+ expect ( hub2 ) . not . toEqual ( hub1 ) ;
68
+ } ) ;
69
+ } ) ;
70
+ } ) ;
71
+
41
72
test ( 'hub single instance' , ( ) => {
42
73
setDomainAsyncContextStrategy ( ) ;
43
74
Original file line number Diff line number Diff line change @@ -44,6 +44,37 @@ conditionalTest({ min: 12 })('async_hooks', () => {
44
44
} ) ;
45
45
} ) ;
46
46
47
+ test ( 'async hub scope inheritance' , async ( ) => {
48
+ setHooksAsyncContextStrategy ( ) ;
49
+
50
+ async function addRandomExtra ( hub : Hub , key : string ) : Promise < void > {
51
+ return new Promise ( resolve => {
52
+ setTimeout ( ( ) => {
53
+ hub . setExtra ( key , Math . random ( ) ) ;
54
+ resolve ( ) ;
55
+ } , 100 ) ;
56
+ } ) ;
57
+ }
58
+
59
+ const globalHub = getCurrentHub ( ) ;
60
+ await addRandomExtra ( globalHub , 'a' ) ;
61
+
62
+ await runWithAsyncContext ( async hub1 => {
63
+ expect ( hub1 ) . toEqual ( globalHub ) ;
64
+
65
+ await addRandomExtra ( hub1 , 'b' ) ;
66
+ expect ( hub1 ) . not . toEqual ( globalHub ) ;
67
+
68
+ await runWithAsyncContext ( async hub2 => {
69
+ expect ( hub2 ) . toEqual ( hub1 ) ;
70
+ expect ( hub2 ) . not . toEqual ( globalHub ) ;
71
+
72
+ await addRandomExtra ( hub1 , 'c' ) ;
73
+ expect ( hub2 ) . not . toEqual ( hub1 ) ;
74
+ } ) ;
75
+ } ) ;
76
+ } ) ;
77
+
47
78
test ( 'context single instance' , ( ) => {
48
79
setHooksAsyncContextStrategy ( ) ;
49
80
You can’t perform that action at this time.
0 commit comments