Files
isp-config-service/service/event/compactor_test.go
T
komissarovyv 439e6f5ebf Drop the module leader recompute event
The queue event did two things: set the routing-changed flag, which the lifecycle
event of the same change already sets, and deliver the leader-change info log. It
cost an extra raft INSERT per connect/disconnect, two GetForLeaderElection reads per
lifecycle event used for nothing else, a payload kind, a compaction key and a
subscription-service method that only logged.

The leader is now logged where it is published: the address-list emission logs the
leader it just sent, and the routing rebuild logs one summary line with the leaders
it published. Modules without election stay silent, as before.

A future self-election needs a recompute trigger that also re-broadcasts the address
list; that event will be added when the requirement exists, not carried as a no-op.
2026-11-19 12:57:28 +03:00

42 lines
1.1 KiB
Go

package event_test
import (
"testing"
"isp-config-service/entity"
"isp-config-service/service/event"
"github.com/stretchr/testify/require"
)
const testModuleId = "test-module-id"
func TestCompactCollapsesModuleLifecycle(t *testing.T) {
t.Parallel()
require := require.New(t)
ready := entity.NewEvent(entity.EventPayload{
ModuleReady: &entity.PayloadModuleReady{ModuleId: testModuleId},
})
ready.Id = 1
disconnected := entity.NewEvent(entity.EventPayload{
ModuleDisconnected: &entity.PayloadModuleDisconnected{ModuleId: testModuleId},
})
disconnected.Id = 2
configUpdated := entity.NewEvent(entity.EventPayload{
ConfigUpdated: &entity.PayloadConfigUpdated{ModuleId: testModuleId},
})
configUpdated.Id = 3
require.Equal("module_lifecycle_"+testModuleId, ready.Key())
require.Equal("module_lifecycle_"+testModuleId, disconnected.Key())
require.Equal("config_updated_"+testModuleId, configUpdated.Key())
compacted := event.NewCompactor().Compact([]entity.Event{ready, disconnected, configUpdated})
require.Equal([]entity.Event{disconnected, configUpdated}, compacted,
"the newest lifecycle event wins, a config update is a key of its own")
}