12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package frankenphp
- import (
- "sync"
- "testing"
- "github.com/stretchr/testify/assert"
- "go.uber.org/zap"
- )
- func TestYieldToEachOtherViaThreadStates(t *testing.T) {
- threadState := &threadStateHandler{currentState: stateBooting}
- go func() {
- threadState.waitFor(stateInactive)
- assert.True(t, threadState.is(stateInactive))
- threadState.set(stateActive)
- }()
- threadState.set(stateInactive)
- threadState.waitFor(stateActive)
- assert.True(t, threadState.is(stateActive))
- }
- func TestYieldToAWaitGroupPassedByThreadState(t *testing.T) {
- logger, _ = zap.NewDevelopment()
- threadState := &threadStateHandler{currentState: stateBooting}
- hasYielded := false
- wg := sync.WaitGroup{}
- wg.Add(1)
- go func() {
- threadState.set(stateInactive)
- threadState.waitForAndYield(&wg, stateActive)
- hasYielded = true
- wg.Done()
- }()
- threadState.waitFor(stateInactive)
- threadState.set(stateActive)
- // 'set' should have yielded to the wait group
- assert.True(t, hasYielded)
- }
|