LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package time_test | 5 package time_test |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "os" | 9 "os" |
10 "syscall" | 10 "syscall" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 ) | 165 ) |
166 // make the result channel buffered because we don't want | 166 // make the result channel buffered because we don't want |
167 // to depend on channel queueing semantics that might | 167 // to depend on channel queueing semantics that might |
168 // possibly change in the future. | 168 // possibly change in the future. |
169 result := make(chan afterResult, len(slots)) | 169 result := make(chan afterResult, len(slots)) |
170 | 170 |
171 t0 := Nanoseconds() | 171 t0 := Nanoseconds() |
172 for _, slot := range slots { | 172 for _, slot := range slots { |
173 go await(slot, result, After(int64(slot)*Delta)) | 173 go await(slot, result, After(int64(slot)*Delta)) |
174 } | 174 } |
175 » sort.SortInts(slots) | 175 » sort.Ints(slots) |
176 for _, slot := range slots { | 176 for _, slot := range slots { |
177 r := <-result | 177 r := <-result |
178 if r.slot != slot { | 178 if r.slot != slot { |
179 return fmt.Errorf("after queue got slot %d, expected %d"
, r.slot, slot) | 179 return fmt.Errorf("after queue got slot %d, expected %d"
, r.slot, slot) |
180 } | 180 } |
181 ns := r.t - t0 | 181 ns := r.t - t0 |
182 target := int64(slot * Delta) | 182 target := int64(slot * Delta) |
183 slop := int64(Delta) / 4 | 183 slop := int64(Delta) / 4 |
184 if ns < target-slop || ns > target+slop { | 184 if ns < target-slop || ns > target+slop { |
185 return fmt.Errorf("after queue slot %d arrived at %g, ex
pected [%g,%g]", slot, float64(ns), float64(target-slop), float64(target+slop)) | 185 return fmt.Errorf("after queue slot %d arrived at %g, ex
pected [%g,%g]", slot, float64(ns), float64(target-slop), float64(target+slop)) |
186 } | 186 } |
187 } | 187 } |
188 return nil | 188 return nil |
189 } | 189 } |
LEFT | RIGHT |