Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Jan 27, 2025
1 parent 7791ae3 commit 9423d7a
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions configx/provider_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func assertNoOpenFDs(t require.TestingT, dir, name string) {
}
var b, be bytes.Buffer
// we are only interested in the file descriptors, so we use the `-F f` option
c := exec.Command("lsof", "-n", "-F", "f", "--", filepath.Join(dir, name))
c := exec.Command("lsof", "-n", "-F", "fc", "--", filepath.Join(dir, name))
c.Stdout = &b
c.Stderr = &be
exitErr := new(exec.ExitError)
Expand All @@ -61,13 +61,22 @@ func TestReload(t *testing.T) {
setup := func(t *testing.T, dir, name string, c chan<- struct{}, modifiers ...OptionModifier) (*Provider, *logrusx.Logger) {
l := logrusx.New("configx", "test")
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
t.Cleanup(func() {
close(c)
cancel()
assertNoOpenFDs(t, dir, name)
})
modifiers = append(modifiers,
WithLogrusWatcher(l),
WithLogger(l),
AttachWatcher(func(event watcherx.Event, err error) {
fmt.Printf("Received event: %+v error: %+v\n", event, err)
c <- struct{}{}
fmt.Printf("Received event: %+v %T error: %+v\n", event, event, err)
select {
case <-ctx.Done():
return
case c <- struct{}{}:
return
}
}),
WithContext(ctx),
)
Expand All @@ -79,12 +88,12 @@ func TestReload(t *testing.T) {
t.Run("case=rejects not validating changes", func(t *testing.T) {
t.Parallel()
dir, name := tmpConfigFile(t, "memory", "bar")
assertNoOpenFDs(t, dir, name)

c := make(chan struct{})
p, l := setup(t, dir, name, c)
hook := test.NewLocal(l.Entry.Logger)

assertNoOpenFDs(t, dir, name)

assert.Equal(t, []*logrus.Entry{}, hook.AllEntries())
assert.Equal(t, "memory", p.String("dsn"))
assert.Equal(t, "bar", p.String("foo"))
Expand Down Expand Up @@ -112,13 +121,12 @@ func TestReload(t *testing.T) {
t.Run("case=rejects to update immutable", func(t *testing.T) {
t.Parallel()
dir, name := tmpConfigFile(t, "memory", "bar")

c := make(chan struct{})
p, l := setup(t, dir, name, c,
WithImmutables("dsn"))
hook := test.NewLocal(l.Entry.Logger)

assertNoOpenFDs(t, dir, name)

assert.Equal(t, []*logrus.Entry{}, hook.AllEntries())
assert.Equal(t, "memory", p.String("dsn"))
assert.Equal(t, "bar", p.String("foo"))
Expand All @@ -133,10 +141,10 @@ func TestReload(t *testing.T) {
assert.Equal(t, "bar", p.String("foo"))

// but it is still watching the files
updateConfigFile(t, c, dir, name, "memory", "bar", "baz")
assert.Equal(t, "baz", p.String("bar"))

assertNoOpenFDs(t, dir, name)
updateConfigFile(t, c, dir, name, "memory", "foo", "bar")
assert.Equal(t, "bar", p.String("bar"))
assert.Equal(t, "foo", p.String("bar"))
assert.Equal(t, "memory", p.String("dsn"))
})

t.Run("case=allows to update excepted immutable", func(t *testing.T) {
Expand Down

0 comments on commit 9423d7a

Please sign in to comment.