github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/mometric/testutil_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // this file contains test utils. Name this file "*_test.go" to make
    16  // compiler ignore it
    17  
    18  package mometric
    19  
    20  import (
    21  	"context"
    22  	"sync"
    23  	"sync/atomic"
    24  )
    25  
    26  // some tests will modify global variables, and something weird
    27  // may happen if they run concurrently.
    28  // use this mutex to make those tests execute sequentially
    29  var configMu *sync.Mutex = new(sync.Mutex)
    30  
    31  func withModifiedConfig(f func()) {
    32  	configMu.Lock()
    33  	defer configMu.Unlock()
    34  	f()
    35  }
    36  
    37  func makeDummyClock(startOffset int64) func() int64 {
    38  	var tick = startOffset - 1
    39  	return func() int64 {
    40  		return atomic.AddInt64(&tick, 1)
    41  	}
    42  }
    43  
    44  type dummySwitch struct{}
    45  
    46  func (dummySwitch) Start(ctx context.Context) bool             { return true }
    47  func (dummySwitch) Stop(graceful bool) (<-chan struct{}, bool) { return nil, false }