Skip to content

Commit 3501f67

Browse files
Conditionally register archival category (#3867)
1 parent 9a4f19e commit 3501f67

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

service/history/queueFactoryBase.go

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"go.temporal.io/server/service/history/configs"
4343
"go.temporal.io/server/service/history/queues"
4444
"go.temporal.io/server/service/history/shard"
45+
"go.temporal.io/server/service/history/tasks"
4546
wcache "go.temporal.io/server/service/history/workflow/cache"
4647
)
4748

@@ -136,8 +137,13 @@ func getQueueFactories(
136137
queueFactorySet.TimerQueueFactory,
137138
queueFactorySet.VisibilityQueueFactory,
138139
}
140+
c := tasks.CategoryArchival
141+
// this will only affect tests because this method is only called once in production,
142+
// but it may be called many times across test runs, which would leave the archival queue as a dangling category
143+
tasks.RemoveCategory(c.ID())
139144
if archivalMetadata.GetHistoryConfig().StaticClusterState() == archiver.ArchivalEnabled || archivalMetadata.GetVisibilityConfig().StaticClusterState() == archiver.ArchivalEnabled {
140145
factories = append(factories, queueFactorySet.ArchivalQueueFactory)
146+
tasks.NewCategory(c.ID(), c.Type(), c.Name())
141147
}
142148
return factories
143149
}

service/history/queue_factory_base_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"testing"
2929

3030
"github.com/golang/mock/gomock"
31+
"github.com/stretchr/testify/assert"
3132
"github.com/stretchr/testify/require"
3233
"go.uber.org/fx"
3334

@@ -45,6 +46,7 @@ import (
4546
"go.temporal.io/server/common/sdk"
4647
"go.temporal.io/server/service/history/archival"
4748
"go.temporal.io/server/service/history/configs"
49+
"go.temporal.io/server/service/history/tasks"
4850
"go.temporal.io/server/service/history/workflow"
4951
"go.temporal.io/server/service/worker/archiver"
5052
)
@@ -93,7 +95,7 @@ type moduleTestCase struct {
9395

9496
// Run runs the test case.
9597
func (c *moduleTestCase) Run(t *testing.T) {
96-
t.Parallel()
98+
9799
controller := gomock.NewController(t)
98100
dependencies := getModuleDependencies(controller, c)
99101
var factories []QueueFactory
@@ -135,8 +137,10 @@ func (c *moduleTestCase) Run(t *testing.T) {
135137
require.NotNil(t, viq)
136138
if c.ExpectArchivalQueue {
137139
require.NotNil(t, aq)
140+
assert.Contains(t, tasks.GetCategories(), tasks.CategoryIDArchival)
138141
} else {
139142
require.Nil(t, aq)
143+
assert.NotContains(t, tasks.GetCategories(), tasks.CategoryIDArchival)
140144
}
141145
}
142146

service/history/tasks/category.go

+8
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ func GetCategories() map[int32]Category {
145145
return maps.Clone(categories.m)
146146
}
147147

148+
// RemoveCategory removes a registered Category.
149+
// This should only be used for testing.
150+
func RemoveCategory(id int32) {
151+
categories.Lock()
152+
defer categories.Unlock()
153+
delete(categories.m, id)
154+
}
155+
148156
// GetCategoryByID returns a registered Category with the same ID
149157
func GetCategoryByID(id int32) (Category, bool) {
150158
categories.RLock()

0 commit comments

Comments
 (0)