MCPcopy
hub / github.com/dropbox/godropbox / TestStripDeadline

Function TestStripDeadline

context2/context_test.go:106–187  ·  view source on GitHub ↗
(outerT *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestStripDeadline(outerT *testing.T) {
107 outerT.Run("DeadlineDoesntPropagate", func(t *testing.T) {
108 timeout := 1 * time.Second
109 ctx, cancel := context.WithTimeout(context.Background(), timeout)
110 defer cancel()
111
112 procrastinator := StripDeadline(ctx)
113
114 deadline, ok := procrastinator.Deadline()
115 if ok {
116 t.Fatal("Procrastinator had a deadline:", deadline)
117 }
118 })
119
120 outerT.Run("DeadlineCausesCancel", func(t *testing.T) {
121 timeout := 1 * time.Second
122 ctx, cancel := context.WithTimeout(context.Background(), timeout)
123 defer cancel()
124
125 procrastinator := StripDeadline(ctx)
126
127 <-procrastinator.Done()
128
129 if procrastinator.Err() == nil {
130 t.Fatal("Expected error")
131 }
132 })
133
134 outerT.Run("CancelPropDown", func(t *testing.T) {
135 parent, parentCancel := context.WithCancel(context.Background())
136 procrastinator := StripDeadline(parent)
137 child, childCancel := context.WithCancel(procrastinator)
138 defer childCancel()
139
140 parentCancel()
141
142 <-child.Done()
143 })
144
145 outerT.Run("CancelPropUp", func(t *testing.T) {
146 parent, parentCancel := context.WithCancel(context.Background())
147 procrastinator := StripDeadline(parent)
148 _, childCancel := context.WithCancel(procrastinator)
149
150 childCancel()
151
152 select {
153 case <-procrastinator.Done():
154 t.Fatal("Procrastinator got cancelled.")
155 case <-parent.Done():
156 t.Fatal("Parent got cancelled.")
157 default:
158 }
159
160 parentCancel()
161
162 <-procrastinator.Done()
163 })

Callers

nothing calls this directly

Calls 5

StripDeadlineFunction · 0.85
ValueMethod · 0.65
DeadlineMethod · 0.45
DoneMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected