mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
test fixture race
This commit is contained in:
parent
0fe38fba6c
commit
c52e3ed37b
@ -2,6 +2,7 @@ package views
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -18,8 +19,14 @@ func TestJSONHook_create(t *testing.T) {
|
||||
streams, done := terminal.StreamsForTesting(t)
|
||||
hook := newJSONHook(NewJSONView(NewView(streams)))
|
||||
|
||||
var nowMu sync.Mutex
|
||||
now := time.Now()
|
||||
hook.timeNow = func() time.Time { return now }
|
||||
hook.timeNow = func() time.Time {
|
||||
nowMu.Lock()
|
||||
defer nowMu.Unlock()
|
||||
return now
|
||||
}
|
||||
|
||||
after := make(chan time.Time, 1)
|
||||
hook.timeAfter = func(time.Duration) <-chan time.Time { return after }
|
||||
|
||||
@ -52,18 +59,24 @@ func TestJSONHook_create(t *testing.T) {
|
||||
|
||||
// Travel 10s into the future, notify the progress goroutine, and sleep
|
||||
// briefly to allow it to execute
|
||||
nowMu.Lock()
|
||||
now = now.Add(10 * time.Second)
|
||||
after <- now
|
||||
nowMu.Unlock()
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
// Travel 10s into the future, notify the progress goroutine, and sleep
|
||||
// briefly to allow it to execute
|
||||
nowMu.Lock()
|
||||
now = now.Add(10 * time.Second)
|
||||
after <- now
|
||||
nowMu.Unlock()
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
// Travel 2s into the future. We have arrived!
|
||||
nowMu.Lock()
|
||||
now = now.Add(2 * time.Second)
|
||||
nowMu.Unlock()
|
||||
|
||||
action, err = hook.PostApply(addr, states.CurrentGen, plannedNewState, nil)
|
||||
testHookReturnValues(t, action, err)
|
||||
|
Loading…
Reference in New Issue
Block a user