This file is indexed.

/usr/share/gocode/src/gopkg.in/tomb.v2/context16_test.go is in golang-gopkg-tomb.v2-dev 0.0~git20161208.d5d1b58-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// +build !go1.7

package tomb_test

import (
	"testing"
	"time"

	"golang.org/x/net/context"

	"gopkg.in/tomb.v2"
)

func TestWithContext(t *testing.T) {
	parent1, cancel1 := context.WithCancel(context.Background())

	tb, child1 := tomb.WithContext(parent1)

	if !tb.Alive() {
		t.Fatalf("WithContext returned dead tomb")
	}
	if tb.Context(parent1) != child1 {
		t.Fatalf("Context returned different context for same parent")
	}
	if tb.Context(nil) != child1 {
		t.Fatalf("Context returned different context for nil parent")
	}
	select {
	case <-child1.Done():
		t.Fatalf("Tomb's child context was born dead")
	default:
	}

	parent2, cancel2 := context.WithCancel(context.WithValue(context.Background(), "parent", "parent2"))
	child2 := tb.Context(parent2)

	if tb.Context(parent2) != child2 {
		t.Fatalf("Context returned different context for same parent")
	}
	if child2.Value("parent") != "parent2" {
		t.Fatalf("Child context didn't inherit its parent's properties")
	}
	select {
	case <-child2.Done():
		t.Fatalf("Tomb's child context was born dead")
	default:
	}

	cancel2()

	select {
	case <-child2.Done():
	case <-time.After(5 * time.Second):
		t.Fatalf("Tomb's child context didn't die after parent was canceled")
	}
	if !tb.Alive() {
		t.Fatalf("Canceling unrelated parent context killed tomb")
	}

	parent3 := context.WithValue(context.Background(), "parent", "parent3")
	child3 := tb.Context(parent3)

	if child3.Value("parent") != "parent3" {
		t.Fatalf("Child context didn't inherit its parent's properties")
	}
	select {
	case <-child3.Done():
		t.Fatalf("Tomb's child context was born dead")
	default:
	}

	cancel1()

	select {
	case <-tb.Dying():
	case <-time.After(5 * time.Second):
		t.Fatalf("Canceling parent context did not kill tomb")
	}

	if tb.Err() != context.Canceled {
		t.Fatalf("tomb should be %v, got %v", context.Canceled, tb.Err())
	}

	if tb.Context(parent1) == child1 || tb.Context(parent3) == child3 {
		t.Fatalf("Tomb is dead and shouldn't be tracking children anymore")
	}
	select {
	case <-child3.Done():
	case <-time.After(5 * time.Second):
		t.Fatalf("Child context didn't die after tomb's death")
	}

	parent4 := context.WithValue(context.Background(), "parent", "parent4")
	child4 := tb.Context(parent4)

	select {
	case <-child4.Done():
	case <-time.After(5 * time.Second):
		t.Fatalf("Child context should be born canceled")
	}

	childnil := tb.Context(nil)
	select {
	case <-childnil.Done():
	default:
		t.Fatalf("Child context should be born canceled")
	}
}

func TestContextNoParent(t *testing.T) {
	var tb tomb.Tomb

	parent2, cancel2 := context.WithCancel(context.WithValue(context.Background(), "parent", "parent2"))
	child2 := tb.Context(parent2)

	if tb.Context(parent2) != child2 {
		t.Fatalf("Context returned different context for same parent")
	}
	if child2.Value("parent") != "parent2" {
		t.Fatalf("Child context didn't inherit its parent's properties")
	}
	select {
	case <-child2.Done():
		t.Fatalf("Tomb's child context was born dead")
	default:
	}

	cancel2()

	select {
	case <-child2.Done():
	default:
		t.Fatalf("Tomb's child context didn't die after parent was canceled")
	}
	if !tb.Alive() {
		t.Fatalf("Canceling unrelated parent context killed tomb")
	}

	parent3 := context.WithValue(context.Background(), "parent", "parent3")
	child3 := tb.Context(parent3)

	if child3.Value("parent") != "parent3" {
		t.Fatalf("Child context didn't inherit its parent's properties")
	}
	select {
	case <-child3.Done():
		t.Fatalf("Tomb's child context was born dead")
	default:
	}

	tb.Kill(nil)

	if tb.Context(parent3) == child3 {
		t.Fatalf("Tomb is dead and shouldn't be tracking children anymore")
	}
	select {
	case <-child3.Done():
	default:
		t.Fatalf("Child context didn't die after tomb's death")
	}

	parent4 := context.WithValue(context.Background(), "parent", "parent4")
	child4 := tb.Context(parent4)

	select {
	case <-child4.Done():
	default:
		t.Fatalf("Child context should be born canceled")
	}

	childnil := tb.Context(nil)
	select {
	case <-childnil.Done():
	default:
		t.Fatalf("Child context should be born canceled")
	}
}