mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
This is a follow-up for 63b8b7b0c4
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6871
33 lines
771 B
Go
33 lines
771 B
Go
package fsutil
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
// IsFsyncDisabled returns true if fsync must be disabled
|
|
//
|
|
// The fsync is disabled in tests, since it significantly slows down tests which work with files.
|
|
// The fsync can be enabled in tests by setting DISABLE_FSYNC_FOR_TESTING environment variable to false.
|
|
//
|
|
// The fsync is enabled for ordinary programs. It can be disabled by setting DISABLE_FSYNC_FOR_TESTING
|
|
// environment variable to true.
|
|
func IsFsyncDisabled() bool {
|
|
return isFsyncDisabled
|
|
}
|
|
|
|
var isFsyncDisabled = isFsyncDisabledInternal()
|
|
|
|
func isFsyncDisabledInternal() bool {
|
|
s := os.Getenv("DISABLE_FSYNC_FOR_TESTING")
|
|
if s == "" {
|
|
return testing.Testing()
|
|
}
|
|
b, err := strconv.ParseBool(s)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return b
|
|
}
|