Пример #1
0
func newStatePoller(m *MonitorProxy, period time.Duration) *StatePoller {
	s := watch.NewScheme()
	expect := &WatchState{}
	s.AddKnownTypes(expect)

	return &StatePoller{
		m:        m,
		scheme:   s,
		period:   period,
		stopChan: make(chan interface{}),
	}
}
Пример #2
0
func TestDecoder(t *testing.T) {

	var eventType watch.EventType

	expect := &WatchState{
		Running:    true,
		Paused:     false,
		Restarting: false,
		Pid:        100,
		ExitCode:   0,
	}
	scheme := watch.NewScheme()
	scheme.AddKnownTypes(expect)

	eventType = watchStateEvent

	out, in := io.Pipe()
	decoder := NewDecoder(out, scheme)
	encoder := NewEncoder(in)
	go func() {
		if err := encoder.Encode(&watch.Event{eventType, expect}); err != nil {
			t.Errorf("Unexpected error %v", err)
		}
		in.Close()
	}()

	done := make(chan struct{})
	go func() {
		r, got, err := decoder.Decode()
		if err != nil {
			t.Fatalf("Unexpected error %v", err)
		}
		if e, a := eventType, r; e != a {
			t.Errorf("Expected %v, got %v", e, a)
		}
		if e, a := expect, got; !reflect.DeepEqual(e, a) {
			t.Errorf("Expected %v, got %v", e, a)
		}
		t.Logf("Exited read")
		close(done)
	}()
	<-done
	decoder.Close()
}