@@ -32,6 +32,7 @@ import (
32
32
"github.com/golang/mock/gomock"
33
33
"github.com/stretchr/testify/assert"
34
34
"github.com/stretchr/testify/require"
35
+ "go.uber.org/fx"
35
36
"go.uber.org/multierr"
36
37
37
38
carchiver "go.temporal.io/server/common/archiver"
@@ -42,6 +43,7 @@ import (
42
43
"go.temporal.io/server/common/quotas"
43
44
"go.temporal.io/server/common/sdk"
44
45
"go.temporal.io/server/common/testing/mocksdk"
46
+ "go.temporal.io/server/service/history/configs"
45
47
)
46
48
47
49
func TestArchiver (t * testing.T ) {
@@ -280,7 +282,38 @@ func TestArchiver(t *testing.T) {
280
282
rateLimiter := quotas .NewMockRateLimiter (controller )
281
283
rateLimiter .EXPECT ().WaitN (gomock .Any (), 2 ).Return (c .RateLimiterWaitErr )
282
284
283
- archiver := NewArchiver (archiverProvider , logRecorder , metricsHandler , rateLimiter )
285
+ // we need this channel to get the Archiver which is created asynchronously
286
+ archivers := make (chan Archiver , 1 )
287
+ // we make an app here so that we can test that the Module is working as intended
288
+ app := fx .New (
289
+ fx .Supply (fx .Annotate (archiverProvider , fx .As (new (provider.ArchiverProvider )))),
290
+ fx .Supply (fx .Annotate (logRecorder , fx .As (new (log.Logger )))),
291
+ fx .Supply (fx .Annotate (metricsHandler , fx .As (new (metrics.Handler )))),
292
+ fx .Supply (& configs.Config {
293
+ ArchivalBackendMaxRPS : func () float64 {
294
+ return 42.0
295
+ },
296
+ }),
297
+ Module ,
298
+ fx .Decorate (func (rl quotas.RateLimiter ) quotas.RateLimiter {
299
+ // we need to decorate the rate limiter so that we can use the mock
300
+ // we also verify that the rate being used is equal to the one in the config
301
+ assert .Equal (t , 42.0 , rl .Rate ())
302
+ return rateLimiter
303
+ }),
304
+ fx .Invoke (func (a Archiver ) {
305
+ // after all parameters are provided, we get the Archiver and put it in the channel
306
+ // so that we can use it in the test
307
+ archivers <- a
308
+ }),
309
+ )
310
+ require .NoError (t , app .Err ())
311
+ // we need to start the app for fx.Invoke to be called, so that we can get the Archiver
312
+ require .NoError (t , app .Start (ctx ))
313
+ defer func () {
314
+ require .NoError (t , app .Stop (ctx ))
315
+ }()
316
+ archiver := <- archivers
284
317
_ , err = archiver .Archive (ctx , & Request {
285
318
HistoryURI : historyURI ,
286
319
VisibilityURI : visibilityURI ,
0 commit comments