(outerT *testing.T)
| 104 | } |
| 105 | |
| 106 | func 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 | }) |
nothing calls this directly
no test coverage detected