mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 19:27:58 +08:00
30 lines
579 B
Go
30 lines
579 B
Go
package testutil
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
|
|
"src.elv.sh/pkg/env"
|
|
)
|
|
|
|
// ScaledMs returns ms milliseconds, scaled by the ELVISH_TEST_TIME_SCALE
|
|
// environment variable. If the variable does not exist, the scale defaults to
|
|
// 1.
|
|
func ScaledMs(ms int) time.Duration {
|
|
return time.Duration(
|
|
float64(ms) * float64(time.Millisecond) * getTestTimeScale())
|
|
}
|
|
|
|
func getTestTimeScale() float64 {
|
|
env := os.Getenv(env.ELVISH_TEST_TIME_SCALE)
|
|
if env == "" {
|
|
return 1
|
|
}
|
|
scale, err := strconv.ParseFloat(env, 64)
|
|
if err != nil || scale <= 0 {
|
|
return 1
|
|
}
|
|
return scale
|
|
}
|