MCPcopy Create free account
hub / github.com/cloud-native-go/examples / TestFuture

Function TestFuture

ch04/future_test.go:29–46  ·  view source on GitHub ↗

TestFuture just runs slow functions, and makes sure that it returns the expected result after the expected amount of time.

(t *testing.T)

Source from the content-addressed store, hash-verified

27// TestFuture just runs slow functions, and makes sure that it returns the
28// expected result after the expected amount of time.
29func TestFuture(t *testing.T) {
30 start := time.Now()
31
32 ctx := context.Background()
33 future := SlowFunction(ctx)
34
35 res, err := future.Result()
36 if err != nil {
37 t.Error(err)
38 return
39 }
40
41 if !strings.HasPrefix(res, "I slept for") {
42 t.Error("unexpected output:", res)
43 }
44
45 elapsedCheck(t, start, 2)
46}
47
48// TestFutureGetTwice tests that subsequent calls to future.Result()
49// immediately return the initial return values.

Callers

nothing calls this directly

Calls 3

SlowFunctionFunction · 0.85
elapsedCheckFunction · 0.85
ResultMethod · 0.65

Tested by

no test coverage detected