Beispiel #1
0
func TestDoProposalTimeout(t *testing.T) {
	srv := &EtcdServer{
		cfg:      &ServerConfig{TickMs: 1},
		r:        raftNode{Node: newNodeNop()},
		w:        wait.NewNop(),
		reqIDGen: idutil.NewGenerator(0, time.Time{}),
	}
	ctx, _ := context.WithTimeout(context.Background(), 0)
	_, err := srv.Do(ctx, pb.Request{Method: "PUT"})
	if err != ErrTimeout {
		t.Fatalf("err = %v, want %v", err, ErrTimeout)
	}
}
Beispiel #2
0
func TestDoProposalStopped(t *testing.T) {
	srv := &EtcdServer{
		cfg:      &ServerConfig{TickMs: 1},
		r:        raftNode{Node: newNodeNop()},
		w:        wait.NewNop(),
		reqIDGen: idutil.NewGenerator(0, time.Time{}),
	}
	srv.done = make(chan struct{})
	close(srv.done)
	_, err := srv.Do(context.Background(), pb.Request{Method: "PUT", ID: 1})
	if err != ErrStopped {
		t.Errorf("err = %v, want %v", err, ErrStopped)
	}
}
Beispiel #3
0
// TestPublishStopped tests that publish will be stopped if server is stopped.
func TestPublishStopped(t *testing.T) {
	srv := &EtcdServer{
		cfg: &ServerConfig{TickMs: 1},
		r: raftNode{
			Node:      newNodeNop(),
			transport: rafthttp.NewNopTransporter(),
		},
		cluster:  &cluster{},
		w:        wait.NewNop(),
		done:     make(chan struct{}),
		stop:     make(chan struct{}),
		reqIDGen: idutil.NewGenerator(0, time.Time{}),
	}
	close(srv.done)
	srv.publish(time.Hour)
}
Beispiel #4
0
// TestPublishRetry tests that publish will keep retry until success.
func TestPublishRetry(t *testing.T) {
	n := newNodeRecorder()
	srv := &EtcdServer{
		cfg:      &ServerConfig{TickMs: 1},
		r:        raftNode{Node: n},
		w:        wait.NewNop(),
		done:     make(chan struct{}),
		reqIDGen: idutil.NewGenerator(0, time.Time{}),
	}
	// TODO: use fakeClockwork
	time.AfterFunc(10*time.Millisecond, func() { close(srv.done) })
	srv.publish(10 * time.Nanosecond)

	action := n.Action()
	// multiple Proposes
	if cnt := len(action); cnt < 2 {
		t.Errorf("len(action) = %d, want >= 2", cnt)
	}
}