mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
54 lines
2.3 KiB
Go
54 lines
2.3 KiB
Go
package execution
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
)
|
|
|
|
// TestCleanup ensures that the cleanup function unregisters the prometheus.Collection
|
|
// also tests the interchangability of the explicit prometheus Register/Unregister
|
|
// and the implicit methods within the collector implementation
|
|
func TestCleanup(t *testing.T) {
|
|
ctx := context.Background()
|
|
pc, err := NewPowchainCollector(ctx)
|
|
assert.NoError(t, err, "Uxpected error caling NewPowchainCollector")
|
|
unregistered := pc.unregister()
|
|
assert.Equal(t, true, unregistered, "PowchainCollector.unregister did not return true (via prometheus.DefaultRegistry)")
|
|
// PowchainCollector is a prometheus.Collector, so we should be able to register it again
|
|
err = prometheus.Register(pc)
|
|
assert.NoError(t, err, "Got error from prometheus.Register after unregistering PowchainCollector")
|
|
// even if it somehow gets registered somewhere else, unregister should work
|
|
unregistered = pc.unregister()
|
|
assert.Equal(t, true, unregistered, "PowchainCollector.unregister failed on the second attempt")
|
|
// and so we should be able to register it again
|
|
err = prometheus.Register(pc)
|
|
assert.NoError(t, err, "Got error from prometheus.Register on the second attempt")
|
|
// ok clean it up one last time for real :)
|
|
unregistered = prometheus.Unregister(pc)
|
|
assert.Equal(t, true, unregistered, "prometheus.Unregister failed to unregister PowchainCollector on final cleanup")
|
|
}
|
|
|
|
// TestCancelation tests that canceling the context passed into
|
|
// NewPowchainCollector cleans everything up as expected. This
|
|
// does come at the cost of an extra channel cluttering up
|
|
// PowchainCollector, just for this test.
|
|
func TestCancelation(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
pc, err := NewPowchainCollector(ctx)
|
|
assert.NoError(t, err, "Uxpected error caling NewPowchainCollector")
|
|
ticker := time.NewTicker(10 * time.Second)
|
|
cancel()
|
|
select {
|
|
case <-ticker.C:
|
|
t.Error("Hit timeout waiting for cancel() to cleanup PowchainCollector")
|
|
case <-pc.finishChan:
|
|
break
|
|
}
|
|
err = prometheus.Register(pc)
|
|
assert.NoError(t, err, "Got error from prometheus.Register after unregistering PowchainCollector through canceled context")
|
|
}
|