Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(engine): improve test coverage, remove dead code #1153

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pkg/route/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ func (engine *Engine) Shutdown(ctx context.Context) (err error) {
if atomic.LoadUint32(&engine.status) != statusRunning {
return errStatusNotRunning
}
if !atomic.CompareAndSwapUint32(&engine.status, statusRunning, statusShutdown) {
return
}

ch := make(chan struct{})
// trigger hooks if any
Expand Down
20 changes: 20 additions & 0 deletions pkg/route/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func TestNew_Engine_WithTransporter(t *testing.T) {
func TestGetTransporterName(t *testing.T) {
name := getTransporterName(&fakeTransporter{})
assert.DeepEqual(t, "route", name)

name = getTransporterName(nil)
assert.DeepEqual(t, "unknown", name)
}

func TestEngineUnescape(t *testing.T) {
Expand Down Expand Up @@ -1029,3 +1032,20 @@ func TestAcquireHijackConn(t *testing.T) {
assert.DeepEqual(t, engine, hijackConn.e)
assert.DeepEqual(t, conn, hijackConn.Conn)
}

func TestMarkAsRunning(t *testing.T) {
// case 1: normal
engine := NewEngine(config.NewOptions(nil))
engine.Init()
err := engine.MarkAsRunning()
assert.DeepEqual(t, err, nil)
assert.DeepEqual(t, statusRunning, atomic.LoadUint32(&engine.status))

// case 2: status is not initialized
engine = NewEngine(config.NewOptions(nil))
engine.Init()
atomic.StoreUint32(&engine.status, statusRunning)
err = engine.MarkAsRunning()
assert.DeepEqual(t, err, errAlreadyRunning)
assert.DeepEqual(t, statusRunning, atomic.LoadUint32(&engine.status))
}
Loading