github.com/MetalBlockchain/metalgo@v1.11.9/vms/proposervm/scheduler/scheduler_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package scheduler 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/stretchr/testify/require" 11 12 "github.com/MetalBlockchain/metalgo/snow/engine/common" 13 "github.com/MetalBlockchain/metalgo/utils/logging" 14 ) 15 16 func TestDelayFromNew(t *testing.T) { 17 toEngine := make(chan common.Message, 10) 18 startTime := time.Now().Add(50 * time.Millisecond) 19 20 s, fromVM := New(logging.NoLog{}, toEngine) 21 defer s.Close() 22 go s.Dispatch(startTime) 23 24 fromVM <- common.PendingTxs 25 26 <-toEngine 27 require.LessOrEqual(t, time.Until(startTime), time.Duration(0)) 28 } 29 30 func TestDelayFromSetTime(t *testing.T) { 31 toEngine := make(chan common.Message, 10) 32 now := time.Now() 33 startTime := now.Add(50 * time.Millisecond) 34 35 s, fromVM := New(logging.NoLog{}, toEngine) 36 defer s.Close() 37 go s.Dispatch(now) 38 39 s.SetBuildBlockTime(startTime) 40 41 fromVM <- common.PendingTxs 42 43 <-toEngine 44 require.LessOrEqual(t, time.Until(startTime), time.Duration(0)) 45 } 46 47 func TestReceipt(*testing.T) { 48 toEngine := make(chan common.Message, 10) 49 now := time.Now() 50 startTime := now.Add(50 * time.Millisecond) 51 52 s, fromVM := New(logging.NoLog{}, toEngine) 53 defer s.Close() 54 go s.Dispatch(now) 55 56 fromVM <- common.PendingTxs 57 58 s.SetBuildBlockTime(startTime) 59 60 <-toEngine 61 }