mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
1b1c45206c
message_gateway scheduled message_gateway:cleanup_pairing_codes every 10 minutes but never registered a task under that pattern, so every dispatch went to a task type with no handler and expired pairing rows accumulated forever, even though repository.DeleteExpiredPairingCodes already existed. Add a test that fails for any schedule whose task pattern is unregistered: it reports the exact orphan rather than relying on a schedule-exists assert.
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package message_gateway_test
|
|
|
|
import (
|
|
"Wavelet/core"
|
|
"Wavelet/plugins/domain/message_gateway"
|
|
"context"
|
|
"io/fs"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMessageGatewayPluginUnit(t *testing.T) {
|
|
ctx := core.NewContext(context.Background())
|
|
p := message_gateway.New()
|
|
assert.Equal(t, "message_gateway", p.Name())
|
|
assert.Equal(t, "1.0.0", p.Manifest().Version)
|
|
require.NoError(t, p.Apply(ctx))
|
|
|
|
// Verify migrations
|
|
entry, ok := ctx.Migrations().Get("message_gateway")
|
|
require.True(t, ok)
|
|
entries, err := fs.ReadDir(entry.FS, entry.Dir)
|
|
require.NoError(t, err)
|
|
assert.NotEmpty(t, entries)
|
|
|
|
// Verify tasks
|
|
task, ok := ctx.Tasks().Get("message_gateway:push_notification")
|
|
require.True(t, ok)
|
|
assert.Equal(t, 3, task.Retry)
|
|
|
|
// Verify schedules
|
|
sched, ok := ctx.Schedules().Get("message_gateway:cleanup_pairing_codes")
|
|
require.True(t, ok)
|
|
assert.Equal(t, "*/10 * * * *", sched.Spec)
|
|
|
|
// Verify settings
|
|
setting, ok := ctx.Settings().Get("message_gateway.max_bindings_per_user")
|
|
require.True(t, ok)
|
|
assert.Equal(t, 5, setting.Default)
|
|
}
|
|
|
|
// TestEveryScheduleHasTaskHandler 回归:RegisterCron 仅登记调度;若同名任务从未
|
|
// Register,则每次触发都投递到无人处理的任务类型,清理逻辑静默失效。
|
|
func TestEveryScheduleHasTaskHandler(t *testing.T) {
|
|
ctx := core.NewContext(context.Background())
|
|
require.NoError(t, message_gateway.New().Apply(ctx))
|
|
|
|
schedules := ctx.Schedules().Schedules()
|
|
require.NotEmpty(t, schedules)
|
|
|
|
for _, sched := range schedules {
|
|
_, ok := ctx.Tasks().Get(sched.TaskType)
|
|
assert.Truef(t, ok, "schedule %q dispatches to task %q, which is never registered",
|
|
sched.Spec, sched.TaskType)
|
|
}
|
|
}
|