core/config: refactor change dispatcher (#4657)

* core/config: refactor change dispatcher

* update test

* close listener go routine when context is canceled

* use cancel cause

* use context

* add more time

* more time
This commit is contained in:
Caleb Doxsey 2023-11-01 13:52:23 -06:00 committed by GitHub
parent 53573dc046
commit e0693e54f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 241 additions and 14 deletions

View file

@ -3,7 +3,9 @@ package config_test
import (
"context"
"errors"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -13,6 +15,8 @@ import (
)
func TestLayeredConfig(t *testing.T) {
t.Parallel()
ctx := context.Background()
t.Run("error on initial build", func(t *testing.T) {
@ -33,12 +37,15 @@ func TestLayeredConfig(t *testing.T) {
})
require.NoError(t, err)
var dst *config.Config
var dst atomic.Pointer[config.Config]
dst.Store(layered.GetConfig())
layered.OnConfigChange(ctx, func(ctx context.Context, c *config.Config) {
dst = c
dst.Store(c)
})
underlying.SetConfig(ctx, &config.Config{Options: &config.Options{DeriveInternalDomainCert: proto.String("b.com")}})
assert.Equal(t, "b.com", dst.Options.GetDeriveInternalDomain())
assert.Eventually(t, func() bool {
return dst.Load().Options.GetDeriveInternalDomain() == "b.com"
}, 10*time.Second, time.Millisecond)
})
}