1
1
/**
2
- * Copyright 2024, Optimizely
2
+ * Copyright 2024-2025 , Optimizely
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -83,24 +83,8 @@ describe('getBatchEventProcessor', () => {
83
83
expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ) . toBe ( undefined ) ;
84
84
} ) ;
85
85
86
- it ( 'uses retry when retryOptions is provided' , ( ) => {
87
- const options = {
88
- eventDispatcher : getMockEventDispatcher ( ) ,
89
- retryOptions : { } ,
90
- defaultFlushInterval : 1000 ,
91
- defaultBatchSize : 10 ,
92
- } ;
93
-
94
- const processor = getBatchEventProcessor ( options ) ;
95
-
96
- expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
97
- const usedRetryConfig = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ;
98
- expect ( usedRetryConfig ) . not . toBe ( undefined ) ;
99
- expect ( usedRetryConfig ?. backoffProvider ) . not . toBe ( undefined ) ;
100
- } ) ;
101
-
102
86
it ( 'uses the correct maxRetries value when retryOptions is provided' , ( ) => {
103
- const options1 = {
87
+ const options = {
104
88
eventDispatcher : getMockEventDispatcher ( ) ,
105
89
defaultFlushInterval : 1000 ,
106
90
defaultBatchSize : 10 ,
@@ -109,34 +93,24 @@ describe('getBatchEventProcessor', () => {
109
93
} ,
110
94
} ;
111
95
112
- const processor1 = getBatchEventProcessor ( options1 ) ;
113
- expect ( Object . is ( processor1 , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
96
+ const processor = getBatchEventProcessor ( options ) ;
97
+ expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
114
98
expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ?. maxRetries ) . toBe ( 10 ) ;
115
-
116
- const options2 = {
117
- eventDispatcher : getMockEventDispatcher ( ) ,
118
- defaultFlushInterval : 1000 ,
119
- defaultBatchSize : 10 ,
120
- retryOptions : { } ,
121
- } ;
122
-
123
- const processor2 = getBatchEventProcessor ( options2 ) ;
124
- expect ( Object . is ( processor2 , MockBatchEventProcessor . mock . instances [ 1 ] ) ) . toBe ( true ) ;
125
- expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ) . not . toBe ( undefined ) ;
126
- expect ( MockBatchEventProcessor . mock . calls [ 1 ] [ 0 ] . retryConfig ?. maxRetries ) . toBe ( undefined ) ;
127
99
} ) ;
128
100
129
101
it ( 'uses exponential backoff with default parameters when retryOptions is provided without backoff values' , ( ) => {
130
102
const options = {
131
103
eventDispatcher : getMockEventDispatcher ( ) ,
132
104
defaultFlushInterval : 1000 ,
133
105
defaultBatchSize : 10 ,
134
- retryOptions : { } ,
106
+ retryOptions : { maxRetries : 2 } ,
135
107
} ;
136
108
137
109
const processor = getBatchEventProcessor ( options ) ;
138
110
expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
139
111
112
+ expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ?. maxRetries ) . toBe ( 2 ) ;
113
+
140
114
const backoffProvider = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ?. backoffProvider ;
141
115
expect ( backoffProvider ) . not . toBe ( undefined ) ;
142
116
const backoff = backoffProvider ?.( ) ;
@@ -149,11 +123,14 @@ describe('getBatchEventProcessor', () => {
149
123
eventDispatcher : getMockEventDispatcher ( ) ,
150
124
defaultFlushInterval : 1000 ,
151
125
defaultBatchSize : 10 ,
152
- retryOptions : { minBackoff : 1000 , maxBackoff : 2000 } ,
126
+ retryOptions : { maxRetries : 2 , minBackoff : 1000 , maxBackoff : 2000 } ,
153
127
} ;
154
128
155
129
const processor = getBatchEventProcessor ( options ) ;
156
130
expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
131
+
132
+ expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ?. maxRetries ) . toBe ( 2 ) ;
133
+
157
134
const backoffProvider = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . retryConfig ?. backoffProvider ;
158
135
159
136
expect ( backoffProvider ) . not . toBe ( undefined ) ;
0 commit comments