File: context_test.go

package info (click to toggle)
golang-github-centrifugal-centrifuge 0.15.0%2Bgit20210306.f435ba2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,612 kB
  • sloc: javascript: 102; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 718 bytes parent folder | download
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
package cancelctx

import (
	"context"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestCustomContext(t *testing.T) {
	ctx, cancel := context.WithCancel(context.Background())
	ch := make(chan struct{})
	customCtx := New(ctx, ch)
	require.NoError(t, customCtx.Err())
	dlTime, dlSet := customCtx.Deadline()
	require.Zero(t, dlTime)
	require.False(t, dlSet)
	select {
	case <-customCtx.Done():
		require.Fail(t, "must not be cancelled")
	default:
	}
	cancel()
	select {
	case <-customCtx.Done():
		require.Fail(t, "must not be cancelled")
	default:
	}
	close(ch)
	select {
	case <-customCtx.Done():
		require.Equal(t, context.Canceled, customCtx.Err())
	default:
		require.Fail(t, "must be cancelled")
	}
}