From aa5a16c4a7f5b801773e783d66a70addbef430d1 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 27 Mar 2026 15:09:05 +0800 Subject: [PATCH] refactor(tests): update synchronization handling in certificate pool tests - Replaced direct initialization of sync.Once instances with pointers to enhance clarity and consistency in the test setup. - Updated the `withTestRootPool` function to use new `doneOnce` variables for managing synchronization, ensuring proper initialization of the root certificate pool and revoked serials. --- commercial/commercial_test.go | 10 ++++++---- commercial/roots.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/commercial/commercial_test.go b/commercial/commercial_test.go index 80cc58f4..7339f4a5 100644 --- a/commercial/commercial_test.go +++ b/commercial/commercial_test.go @@ -23,11 +23,13 @@ func withTestRootPool(t *testing.T, ca *testCA, revoked []*big.Int) { pool := x509.NewCertPool() pool.AddCert(ca.Cert) rootPool = pool - rootPoolOnce = sync.Once{} - rootPoolOnce.Do(func() {}) // mark as done so RootPool() returns our pool + doneOnce := &sync.Once{} + doneOnce.Do(func() {}) // pre-mark as done so RootPool() returns our pool + rootPoolOnce = doneOnce revokedSerials = revoked - revokedOnce = sync.Once{} - revokedOnce.Do(func() {}) // mark as done + doneOnce2 := &sync.Once{} + doneOnce2.Do(func() {}) + revokedOnce = doneOnce2 t.Cleanup(func() { rootPool = origPool diff --git a/commercial/roots.go b/commercial/roots.go index 03d0dfd0..839bb834 100644 --- a/commercial/roots.go +++ b/commercial/roots.go @@ -19,10 +19,10 @@ var rootCA2PEM []byte var revokedJSON []byte var ( - rootPoolOnce sync.Once + rootPoolOnce = &sync.Once{} rootPool *x509.CertPool - revokedOnce sync.Once + revokedOnce = &sync.Once{} revokedSerials []*big.Int )