MCPcopy Create free account
hub / github.com/erpc/erpc / TestCounterInt64_IsStale

Function TestCounterInt64_IsStale

data/shared_state_variable_test.go:564–598  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

562}
563
564func TestCounterInt64_IsStale(t *testing.T) {
565 tests := []struct {
566 name string
567 lastProcessed time.Time
568 staleness time.Duration
569 expected bool
570 }{
571 {
572 name: "not stale",
573 lastProcessed: time.Now(),
574 staleness: time.Second,
575 expected: false,
576 },
577 {
578 name: "stale",
579 lastProcessed: time.Now().Add(-2 * time.Second),
580 staleness: time.Second,
581 expected: true,
582 },
583 {
584 name: "exactly at staleness threshold",
585 lastProcessed: time.Now().Add(-time.Second),
586 staleness: time.Second,
587 expected: true,
588 },
589 }
590
591 for _, tt := range tests {
592 t.Run(tt.name, func(t *testing.T) {
593 counter := &counterInt64{}
594 counter.updatedAtUnixMs.Store(tt.lastProcessed.UnixMilli())
595 assert.Equal(t, tt.expected, counter.IsStale(tt.staleness))
596 })
597 }
598}
599
600// Test that calling setValue directly (as done by remote update watchers or initial value fetch) refreshes the
601// internal lastUpdated timestamp so that subsequent IsStale checks reflect the recent update.

Callers

nothing calls this directly

Calls 4

StoreMethod · 0.80
AddMethod · 0.65
RunMethod · 0.65
IsStaleMethod · 0.65

Tested by

no test coverage detected