go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/matchmaker/pkg/sim/clock_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package sim
     9  
    10  import (
    11  	"testing"
    12  	"time"
    13  
    14  	"go.charczuk.com/sdk/assert"
    15  )
    16  
    17  func Test_simulatedClock_basic(t *testing.T) {
    18  	c := new(simulatedClock)
    19  	assert.ItsTrue(t, c.Now().IsZero())
    20  	c.Wait(500 * time.Millisecond)
    21  	assert.ItsFalse(t, c.Now().IsZero())
    22  }
    23  
    24  func Test_simulatedClock_StartAt(t *testing.T) {
    25  	startAt := time.Date(2023, 12, 25, 17, 28, 00, 00, time.UTC)
    26  	c := NewSimulatedClock(startAt)
    27  	assert.ItsFalse(t, c.Now().IsZero())
    28  	c.Wait(500 * time.Millisecond)
    29  	assert.ItsEqual(t, startAt.Add(500*time.Millisecond), c.Now())
    30  }