Skip to content

Commit

Permalink
Updated with a few more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Jul 10, 2024
1 parent f24b16e commit cfcaf3e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions restest/mockconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ func (c *MockConn) AssertNoSubscription(subj string) {
func (c *MockConn) GetMsg() *Msg {
select {
case r := <-c.rch:
// Channel is closed
if r == nil {
return nil
}
return &Msg{
Msg: r,
c: c,
Expand Down
4 changes: 4 additions & 0 deletions restest/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func NewSession(t *testing.T, service *res.Service, opts ...func(*SessionConfig)

if !s.cfg.NoReset {
msg := s.GetMsg()
if msg == nil {
// The channel is closed
t.Fatal("expected a system.reset, but got no message")
}
if s.cfg.ValidateReset {
msg.AssertSystemReset(cfg.ResetResources, cfg.ResetAccess)
} else {
Expand Down
50 changes: 50 additions & 0 deletions test/00service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,53 @@ func TestServiceTokenReset(t *testing.T) {
})
}
}

// Test ServiceSetWorkerCount panics when called after starting service
func TestServiceSetWorkerCount_AfterStart_Panics(t *testing.T) {
runTest(t, func(s *res.Service) {
s.Handle("model", res.Access(res.AccessGranted))
}, func(s *restest.Session) {
restest.AssertPanic(t, func() {
s.Service().SetWorkerCount(5)
})
})
}

// Test ServiceSetWorkerCount does not panic when zero
func TestServiceSetWorkerCount_ZeroWorkerCount_DoesNotPanic(t *testing.T) {
runTest(t, func(s *res.Service) {
s.SetWorkerCount(0) // Default worker count should be used
}, nil, restest.WithoutReset)
}

// Test ServiceSetWorkerCount does not panic when greater than zero
func TestServiceSetWorkerCount_GreaterThanZero_DoesNotPanic(t *testing.T) {
runTest(t, func(s *res.Service) {
s.SetWorkerCount(5)
}, nil, restest.WithoutReset)
}

// Test ServiceSetInChannelSize panics when called after starting service
func TestServiceSetInChannelSize_AfterStart_Panics(t *testing.T) {
runTest(t, func(s *res.Service) {
s.Handle("model", res.Access(res.AccessGranted))
}, func(s *restest.Session) {
restest.AssertPanic(t, func() {
s.Service().SetInChannelSize(10)
})
})
}

// Test ServiceSetInChannelSize does not panic when zero
func TestServiceSetInChannelSize_ZeroWorkerCount_DoesNotPanic(t *testing.T) {
runTest(t, func(s *res.Service) {
s.SetInChannelSize(0) // Default in channel size should be used
}, nil, restest.WithoutReset)
}

// Test ServiceSetInChannelSize does not panic when greater than zero
func TestServiceSetInChannelSize_GreaterThanZero_DoesNotPanic(t *testing.T) {
runTest(t, func(s *res.Service) {
s.SetInChannelSize(10)
}, nil, restest.WithoutReset)
}

0 comments on commit cfcaf3e

Please sign in to comment.