app/vmstorage: prepare for integration tests with multiple Init / Stop cycles

This commit is contained in:
Aliaksandr Valialkin 2019-07-11 15:34:50 +03:00
parent d031e04023
commit 101fa258e5

View file

@ -28,11 +28,20 @@ var (
// Init initializes vmstorage.
func Init() {
InitWithoutMetrics()
registerStorageMetrics()
}
// InitWithoutMetrics must be called instead of Init inside tests.
//
// This allows multiple Init / Stop cycles.
func InitWithoutMetrics() {
if err := encoding.CheckPrecisionBits(uint8(*precisionBits)); err != nil {
logger.Fatalf("invalid `-precisionBits`: %s", err)
}
logger.Infof("opening storage at %q with retention period %d months", *DataPath, *retentionPeriod)
startTime := time.Now()
WG = syncwg.WaitGroup{}
strg, err := storage.OpenStorage(*DataPath, *retentionPeriod)
if err != nil {
logger.Fatalf("cannot open a storage at %s with retention period %d months: %s", *DataPath, *retentionPeriod, err)
@ -48,8 +57,6 @@ func Init() {
sizeBytes := tm.SmallSizeBytes + tm.BigSizeBytes
logger.Infof("successfully opened storage %q in %s; partsCount: %d; blocksCount: %d; rowsCount: %d; sizeBytes: %d",
*DataPath, time.Since(startTime), partsCount, blocksCount, rowsCount, sizeBytes)
registerStorageMetrics(Storage)
}
// Storage is a storage.
@ -212,7 +219,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
}
}
func registerStorageMetrics(strg *storage.Storage) {
func registerStorageMetrics() {
mCache := &storage.Metrics{}
var mCacheLock sync.Mutex
var lastUpdateTime time.Time
@ -224,7 +231,7 @@ func registerStorageMetrics(strg *storage.Storage) {
return mCache
}
var mc storage.Metrics
strg.UpdateMetrics(&mc)
Storage.UpdateMetrics(&mc)
mCache = &mc
lastUpdateTime = time.Now()
return mCache