fix project3c test filter

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
This commit is contained in:
Connor1996 2020-05-26 11:16:41 +08:00
parent b6d7c442e3
commit bc06cdf987
4 changed files with 1 additions and 92 deletions

View File

@ -82,7 +82,7 @@ project3b:
$(GOTEST) ./kv/test_raftstore -run 3B
project3c:
$(GOTEST) ./scheduler/... -run 3C
$(GOTEST) ./scheduler/server ./scheduler/server/schedulers -check.f="3C"
project4: project4a project4b project4c

View File

@ -297,10 +297,6 @@ func (s *Server) IsClosed() bool {
// Run runs the pd server.
func (s *Server) Run(ctx context.Context) error {
go StartMonitor(ctx, time.Now, func() {
log.Error("system time jumps backward")
})
if err := s.startEtcd(ctx); err != nil {
return err
}

View File

@ -1,41 +0,0 @@
// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package server
import (
"context"
"time"
"github.com/pingcap/log"
"go.uber.org/zap"
)
// StartMonitor calls systimeErrHandler if system time jump backward.
func StartMonitor(ctx context.Context, now func() time.Time, systimeErrHandler func()) {
log.Info("start system time monitor")
tick := time.NewTicker(100 * time.Millisecond)
defer tick.Stop()
for {
last := now().UnixNano()
select {
case <-tick.C:
if now().UnixNano() < last {
log.Error("system time jump backward", zap.Int64("last", last))
systimeErrHandler()
}
case <-ctx.Done():
return
}
}
}

View File

@ -1,46 +0,0 @@
// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package server
import (
"context"
"sync/atomic"
"testing"
"time"
)
func TestSystimeMonitor(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var jumpForward int32
trigged := false
go StartMonitor(ctx,
func() time.Time {
if !trigged {
trigged = true
return time.Now()
}
return time.Now().Add(-2 * time.Second)
}, func() {
atomic.StoreInt32(&jumpForward, 1)
})
time.Sleep(1 * time.Second)
if atomic.LoadInt32(&jumpForward) != 1 {
t.Error("should detect time error")
}
}