forked from hashicorp/raft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
future_test.go
45 lines (40 loc) · 993 Bytes
/
future_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package raft
import (
"errors"
"testing"
)
func TestDeferFutureSuccess(t *testing.T) {
var f deferError
f.init()
f.respond(nil)
if err := f.Error(); err != nil {
t.Fatalf("unexpected error result; got %#v want nil", err)
}
if err := f.Error(); err != nil {
t.Fatalf("unexpected error result; got %#v want nil", err)
}
}
func TestDeferFutureError(t *testing.T) {
want := errors.New("x")
var f deferError
f.init()
f.respond(want)
if got := f.Error(); got != want {
t.Fatalf("unexpected error result; got %#v want %#v", got, want)
}
if got := f.Error(); got != want {
t.Fatalf("unexpected error result; got %#v want %#v", got, want)
}
}
func TestDeferFutureConcurrent(t *testing.T) {
// Food for the race detector.
want := errors.New("x")
var f deferError
f.init()
go f.respond(want)
if got := f.Error(); got != want {
t.Errorf("unexpected error result; got %#v want %#v", got, want)
}
}