fix race
This commit is contained in:
parent
47fd4d2bf7
commit
c4f9e22aeb
|
@ -19,7 +19,6 @@ import (
|
|||
"github.com/hashicorp/nomad/plugins/shared/loader"
|
||||
psstructs "github.com/hashicorp/nomad/plugins/shared/structs"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/kr/pretty"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -306,7 +305,6 @@ func TestManager_DeviceStats(t *testing.T) {
|
|||
stats := m.AllStats()
|
||||
l := len(stats)
|
||||
if l == 2 {
|
||||
t.Logf("% #v", pretty.Formatter(stats))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ func ErrorReserve(err error) ReserveFn {
|
|||
}
|
||||
}
|
||||
|
||||
// StaticStats returns the passed statistics only updating the timestamp
|
||||
// StaticStats returns the passed statistics
|
||||
func StaticStats(out []*DeviceGroupStats) StatsFn {
|
||||
return func(ctx context.Context, intv time.Duration) (<-chan *StatsResponse, error) {
|
||||
outCh := make(chan *StatsResponse, 1)
|
||||
|
@ -86,13 +86,6 @@ func StaticStats(out []*DeviceGroupStats) StatsFn {
|
|||
ticker.Reset(intv)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for _, g := range out {
|
||||
for _, i := range g.InstanceStats {
|
||||
i.Timestamp = now
|
||||
}
|
||||
}
|
||||
|
||||
outCh <- &StatsResponse{
|
||||
Groups: out,
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package loader
|
|||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
|
@ -47,10 +48,13 @@ func (m *MockInstance) Exited() bool { return
|
|||
// plugin returning it has been exited after kill is called. It returns the
|
||||
// passed inst as the plugin
|
||||
func MockBasicExternalPlugin(inst interface{}) *MockInstance {
|
||||
var killedLock sync.Mutex
|
||||
killed := helper.BoolToPtr(false)
|
||||
return &MockInstance{
|
||||
InternalPlugin: false,
|
||||
KillF: func() {
|
||||
killedLock.Lock()
|
||||
defer killedLock.Unlock()
|
||||
*killed = true
|
||||
},
|
||||
|
||||
|
@ -71,6 +75,8 @@ func MockBasicExternalPlugin(inst interface{}) *MockInstance {
|
|||
},
|
||||
|
||||
ExitedF: func() bool {
|
||||
killedLock.Lock()
|
||||
defer killedLock.Unlock()
|
||||
return *killed
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue