mirror of
https://github.com/golang/go
synced 2024-11-23 11:40:07 -07:00
53fd522c0d
Follows suit with https://go-review.googlesource.com/#/c/20111. Generated by running $ grep -R 'Go Authors. All' * | cut -d":" -f1 | while read F;do perl -pi -e 's/Go Authors. All/Go Authors. All/g' $F;done The code in cmd/internal/unvendor wasn't changed. Fixes #15213 Change-Id: I4f235cee0a62ec435f9e8540a1ec08ae03b1a75f Reviewed-on: https://go-review.googlesource.com/21819 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cgotest
|
|
|
|
/*
|
|
// mysleep returns the absolute start time in ms.
|
|
long long mysleep(int seconds);
|
|
|
|
// twoSleep returns the absolute start time of the first sleep
|
|
// in ms.
|
|
long long twoSleep(int);
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var sleepDone = make(chan int64)
|
|
|
|
// parallelSleep returns the absolute difference between the start time
|
|
// of the two sleeps.
|
|
func parallelSleep(n int) int64 {
|
|
t := int64(C.twoSleep(C.int(n))) - <-sleepDone
|
|
if t < 0 {
|
|
return -t
|
|
}
|
|
return t
|
|
}
|
|
|
|
//export BackgroundSleep
|
|
func BackgroundSleep(n int32) {
|
|
go func() {
|
|
sleepDone <- int64(C.mysleep(C.int(n)))
|
|
}()
|
|
}
|
|
|
|
func testParallelSleep(t *testing.T) {
|
|
sleepSec := 1
|
|
dt := time.Duration(parallelSleep(sleepSec)) * time.Millisecond
|
|
t.Logf("difference in start time for two sleep(%d) is %v", sleepSec, dt)
|
|
// bug used to run sleeps in serial, producing a 2*sleepSec-second delay.
|
|
// we detect if the start times of those sleeps are > 0.5*sleepSec-second.
|
|
if dt >= time.Duration(sleepSec)*time.Second/2 {
|
|
t.Fatalf("parallel %d-second sleeps slept for %f seconds", sleepSec, dt.Seconds())
|
|
}
|
|
}
|