Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee we finish writing to the test log before the test exits. #22727

Merged
merged 1 commit into from Mar 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 29 additions & 1 deletion plugin/pkg/scheduler/scheduler_test.go
Expand Up @@ -18,8 +18,10 @@ package scheduler

import (
"errors"
"fmt"
"math/rand"
"reflect"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -158,8 +160,34 @@ func TestScheduler(t *testing.T) {
}

func TestSchedulerForgetAssumedPodAfterDelete(t *testing.T) {
// Set up a channel through which we'll funnel log messages from the watcher.
// This way, we can guarantee that when the test ends no thread will still be
// trying to write to t.Logf (which it would if we handed t.Logf directly to
// StartLogging).
ch := make(chan string)
done := make(chan struct{})
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case msg := <-ch:
t.Log(msg)
case <-done:
return
}
}
}()
eventBroadcaster := record.NewBroadcaster()
defer eventBroadcaster.StartLogging(t.Logf).Stop()
watcher := eventBroadcaster.StartLogging(func(format string, args ...interface{}) {
ch <- fmt.Sprintf(format, args...)
})
defer func() {
watcher.Stop()
close(done)
wg.Wait()
}()

// Setup modeler so we control the contents of all 3 stores: assumed,
// scheduled and queued
Expand Down