Skip to content

Commit

Permalink
Merge pull request #1453 from openziti/fix-manual-start-test
Browse files Browse the repository at this point in the history
Fix manual start test
  • Loading branch information
plorenz authored Oct 19, 2023
2 parents 4c837b0 + aa3150f commit 9066510
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/accept_manual_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ package tests

import (
"github.com/michaelquigley/pfxlog"
"github.com/openziti/ziti/controller/xt"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/ziti/controller/change"
"github.com/openziti/ziti/controller/xt"
"github.com/pkg/errors"
"sync/atomic"
"testing"
Expand All @@ -34,7 +35,9 @@ func Test_ManualStart(t *testing.T) {
defer ctx.Teardown()
ctx.StartServer()

xt.GlobalRegistry().RegisterFactory(&testFailoverStrategyFactory{})
xt.GlobalRegistry().RegisterFactory(&testFailoverStrategyFactory{
ctx: ctx,
})
t.Run("creating service and edge router", func(t *testing.T) {
ctx.testContextChanged(t)
ctx.RequireAdminManagementApiLogin()
Expand Down Expand Up @@ -165,25 +168,35 @@ func Test_ManualStart(t *testing.T) {
})
}

type testFailoverStrategyFactory struct{}
type testFailoverStrategyFactory struct {
ctx *TestContext
}

func (self *testFailoverStrategyFactory) GetStrategyName() string {
return "test-failover"
}

func (self *testFailoverStrategyFactory) NewStrategy() xt.Strategy {
return &testFailoverStrategy{}
return &testFailoverStrategy{
ctx: self.ctx,
}
}

type testFailoverStrategy struct {
xt.DefaultEventVisitor
failCount int32
ctx *TestContext
}

func (self *testFailoverStrategy) VisitDialFailed(event xt.TerminatorEvent) {
failCount := atomic.AddInt32(&self.failCount, 1)
if failCount >= 3 {
xt.GlobalCosts().SetPrecedence(event.GetTerminator().GetId(), xt.Precedences.Failed)
mgr := self.ctx.EdgeController.AppEnv.Managers.Terminator
t, err := mgr.Read(event.GetTerminator().GetId())
self.ctx.Req.NoError(err)
t.Precedence = xt.Precedences.Failed
err = mgr.Update(t, nil, change.New())
self.ctx.Req.NoError(err)
}
}

Expand Down

0 comments on commit 9066510

Please sign in to comment.