Source file 
src/testing/testing_windows.go
     1  
     2  
     3  
     4  
     5  
     6  
     7  package testing
     8  
     9  import (
    10  	"errors"
    11  	"internal/syscall/windows"
    12  	"math/bits"
    13  	"syscall"
    14  	"time"
    15  )
    16  
    17  
    18  
    19  func isWindowsRetryable(err error) bool {
    20  	for {
    21  		unwrapped := errors.Unwrap(err)
    22  		if unwrapped == nil {
    23  			break
    24  		}
    25  		err = unwrapped
    26  	}
    27  	if err == syscall.ERROR_ACCESS_DENIED {
    28  		return true 
    29  	}
    30  	if err == windows.ERROR_SHARING_VIOLATION {
    31  		return true 
    32  	}
    33  	return false
    34  }
    35  
    36  
    37  
    38  
    39  
    40  
    41  
    42  type highPrecisionTime struct {
    43  	now int64
    44  }
    45  
    46  
    47  func highPrecisionTimeNow() highPrecisionTime {
    48  	var t highPrecisionTime
    49  	
    50  	t.now = windows.QueryPerformanceCounter()
    51  	return t
    52  }
    53  
    54  func (a highPrecisionTime) sub(b highPrecisionTime) time.Duration {
    55  	delta := a.now - b.now
    56  
    57  	if queryPerformanceFrequency == 0 {
    58  		queryPerformanceFrequency = windows.QueryPerformanceFrequency()
    59  	}
    60  	hi, lo := bits.Mul64(uint64(delta), uint64(time.Second)/uint64(time.Nanosecond))
    61  	quo, _ := bits.Div64(hi, lo, uint64(queryPerformanceFrequency))
    62  	return time.Duration(quo)
    63  }
    64  
    65  var queryPerformanceFrequency int64
    66  
    67  
    68  func highPrecisionTimeSince(a highPrecisionTime) time.Duration {
    69  	return highPrecisionTimeNow().sub(a)
    70  }
    71  
View as plain text