mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
115 lines
3.4 KiB
Go
115 lines
3.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestStartNodeOnlineRedeploySkipsRecentReconnects(t *testing.T) {
|
|
h := &Handler{
|
|
pendingUpgradeRedeploy: map[int64]struct{}{},
|
|
nodeOnlineRedeployAt: map[int64]time.Time{},
|
|
nodeOnlineRedeployQueued: map[int64]struct{}{},
|
|
nodeOnlineRedeploying: map[int64]struct{}{},
|
|
}
|
|
now := time.Now()
|
|
|
|
if !h.startNodeOnlineRedeploy(54, now) {
|
|
t.Fatalf("expected first reconnect to redeploy")
|
|
}
|
|
h.finishNodeOnlineRedeploy(54)
|
|
|
|
if h.startNodeOnlineRedeploy(54, now.Add(5*time.Second)) {
|
|
t.Fatalf("expected recent reconnect to skip redeploy")
|
|
}
|
|
if h.consumeNodePendingUpgradeRedeploy(54) {
|
|
t.Fatalf("did not expect pending upgrade marker to be consumed")
|
|
}
|
|
}
|
|
|
|
func TestStartNodeOnlineRedeployAllowsPendingUpgradeDuringCooldown(t *testing.T) {
|
|
h := &Handler{
|
|
pendingUpgradeRedeploy: map[int64]struct{}{},
|
|
nodeOnlineRedeployAt: map[int64]time.Time{},
|
|
nodeOnlineRedeployQueued: map[int64]struct{}{},
|
|
nodeOnlineRedeploying: map[int64]struct{}{},
|
|
}
|
|
now := time.Now()
|
|
|
|
if !h.startNodeOnlineRedeploy(54, now) {
|
|
t.Fatalf("expected first reconnect to redeploy")
|
|
}
|
|
h.finishNodeOnlineRedeploy(54)
|
|
h.markNodePendingUpgradeRedeploy(54)
|
|
|
|
if !h.startNodeOnlineRedeploy(54, now.Add(5*time.Second)) {
|
|
t.Fatalf("expected pending upgrade reconnect to bypass cooldown")
|
|
}
|
|
if h.consumeNodePendingUpgradeRedeploy(54) {
|
|
t.Fatalf("expected pending upgrade marker to be consumed during redeploy")
|
|
}
|
|
}
|
|
|
|
func TestStartNodeOnlineRedeployQueuesCooldownReconnect(t *testing.T) {
|
|
h := &Handler{
|
|
pendingUpgradeRedeploy: map[int64]struct{}{},
|
|
nodeOnlineRedeployAt: map[int64]time.Time{},
|
|
nodeOnlineRedeployQueued: map[int64]struct{}{},
|
|
nodeOnlineRedeploying: map[int64]struct{}{},
|
|
}
|
|
now := time.Now()
|
|
|
|
if !h.startNodeOnlineRedeploy(54, now) {
|
|
t.Fatalf("expected first reconnect to redeploy")
|
|
}
|
|
h.finishNodeOnlineRedeploy(54)
|
|
|
|
if h.startNodeOnlineRedeploy(54, now.Add(5*time.Second)) {
|
|
t.Fatalf("expected cooldown reconnect to skip immediate redeploy")
|
|
}
|
|
h.upgradeMu.Lock()
|
|
_, queued := h.nodeOnlineRedeployQueued[54]
|
|
h.upgradeMu.Unlock()
|
|
if !queued {
|
|
t.Fatalf("expected cooldown reconnect to queue a follow-up redeploy")
|
|
}
|
|
}
|
|
|
|
func TestStartNodeOnlineRedeployKeepsPendingUpgradeWhileInFlight(t *testing.T) {
|
|
h := &Handler{
|
|
pendingUpgradeRedeploy: map[int64]struct{}{},
|
|
nodeOnlineRedeployAt: map[int64]time.Time{},
|
|
nodeOnlineRedeployQueued: map[int64]struct{}{},
|
|
nodeOnlineRedeploying: map[int64]struct{}{},
|
|
}
|
|
now := time.Now()
|
|
|
|
if !h.startNodeOnlineRedeploy(54, now) {
|
|
t.Fatalf("expected first reconnect to redeploy")
|
|
}
|
|
h.markNodePendingUpgradeRedeploy(54)
|
|
|
|
if h.startNodeOnlineRedeploy(54, now.Add(time.Second)) {
|
|
t.Fatalf("expected in-flight redeploy to suppress parallel restart")
|
|
}
|
|
if !h.consumeNodePendingUpgradeRedeploy(54) {
|
|
t.Fatalf("expected pending upgrade marker to remain for the next retry")
|
|
}
|
|
h.finishNodeOnlineRedeploy(54)
|
|
}
|
|
|
|
func TestNextNodeOnlineRedeployFireAtDefersExpiredInFlightReconnect(t *testing.T) {
|
|
now := time.Now()
|
|
last := now.Add(-nodeOnlineRedeployCooldown - 5*time.Second)
|
|
|
|
fireAt, start := nextNodeOnlineRedeployFireAt(last, now, false, true)
|
|
if start {
|
|
t.Fatalf("expected in-flight reconnect to queue instead of starting immediately")
|
|
}
|
|
|
|
want := now.Add(nodeOnlineRedeployCooldown)
|
|
if !fireAt.Equal(want) {
|
|
t.Fatalf("expected queued reconnect at %s, got %s", want, fireAt)
|
|
}
|
|
}
|