infra/op-conductor-mon/pkg/monitor/poll_test.go
felipe 28bb7461e9
feat: op-conductor-mon (#1)
* feat: op-conductor-mon

* Update CODEOWNERS
2024-05-24 14:34:07 -07:00

28 lines
664 B
Go

package monitor
import (
"context"
"testing"
"time"
"github.com/ethereum-optimism/optimism/op-conductor-mon/pkg/config"
"github.com/stretchr/testify/require"
)
func TestNetwork_cleanupState(t *testing.T) {
t.Run("should remove expired state", func(t *testing.T) {
n := &Poller{
config: &config.Config{NodeStateExpiration: 10 * time.Hour},
state: map[string]*NodeState{
"clean_me": {updatedAt: time.Now().Add(-11 * time.Hour)},
"keep_me": {updatedAt: time.Now()},
},
}
ctx := context.Background()
require.Equal(t, 2, len(n.state))
n.cleanup(ctx)
require.Equal(t, 1, len(n.state))
require.NotNil(t, n.state["keep_me"])
})
}