49 lines
966 B
Go
49 lines
966 B
Go
|
|
package app
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestStartScheduleAutoPublishReturnsAfterScheduling(t *testing.T) {
|
||
|
|
previousRunner := runScheduleAutoPublishBackground
|
||
|
|
defer func() {
|
||
|
|
runScheduleAutoPublishBackground = previousRunner
|
||
|
|
}()
|
||
|
|
|
||
|
|
started := make(chan struct{})
|
||
|
|
release := make(chan struct{})
|
||
|
|
done := make(chan struct{})
|
||
|
|
runScheduleAutoPublishBackground = func(fn func()) {
|
||
|
|
go func() {
|
||
|
|
close(started)
|
||
|
|
<-release
|
||
|
|
fn()
|
||
|
|
close(done)
|
||
|
|
}()
|
||
|
|
}
|
||
|
|
|
||
|
|
StartScheduleAutoPublish(ScheduleAutoPublishInput{
|
||
|
|
InputParams: map[string]interface{}{
|
||
|
|
"schedule_auto_publish": true,
|
||
|
|
},
|
||
|
|
})
|
||
|
|
|
||
|
|
select {
|
||
|
|
case <-started:
|
||
|
|
case <-time.After(time.Second):
|
||
|
|
t.Fatalf("background runner was not scheduled")
|
||
|
|
}
|
||
|
|
select {
|
||
|
|
case <-done:
|
||
|
|
t.Fatalf("auto publish should not block caller until background work completes")
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
close(release)
|
||
|
|
select {
|
||
|
|
case <-done:
|
||
|
|
case <-time.After(time.Second):
|
||
|
|
t.Fatalf("background auto publish did not finish")
|
||
|
|
}
|
||
|
|
}
|