...

Source file src/k8s.io/utils/clock/testing/simple_interval_clock.go

Documentation: k8s.io/utils/clock/testing

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package testing
    18  
    19  import (
    20  	"time"
    21  
    22  	"k8s.io/utils/clock"
    23  )
    24  
    25  var (
    26  	_ = clock.PassiveClock(&SimpleIntervalClock{})
    27  )
    28  
    29  // SimpleIntervalClock implements clock.PassiveClock, but each invocation of Now steps the clock forward the specified duration
    30  type SimpleIntervalClock struct {
    31  	Time     time.Time
    32  	Duration time.Duration
    33  }
    34  
    35  // Now returns i's time.
    36  func (i *SimpleIntervalClock) Now() time.Time {
    37  	i.Time = i.Time.Add(i.Duration)
    38  	return i.Time
    39  }
    40  
    41  // Since returns time since the time in i.
    42  func (i *SimpleIntervalClock) Since(ts time.Time) time.Duration {
    43  	return i.Time.Sub(ts)
    44  }
    45  

View as plain text