Skip to content

Commit

Permalink
Send the lh update worker into its own routine instead of taking over…
Browse files Browse the repository at this point in the history
… the reload routine
  • Loading branch information
nbrownus committed Jul 25, 2023
1 parent e5af94e commit c9070e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (lh *LightHouse) reload(c *config.C, initial bool) error {
lh.updateCancel()
}

lh.LhUpdateWorker(lh.updateParentCtx, lh.updateUdp)
go lh.LhUpdateWorker(lh.updateParentCtx, lh.updateUdp)
}
}

Expand Down
26 changes: 26 additions & 0 deletions lighthouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,32 @@ func Test_lhStaticMapping(t *testing.T) {
assert.EqualError(t, err, "lighthouse 10.128.0.3 does not have a static_host_map entry")
}

func TestReloadLighthouseInterval(t *testing.T) {
l := test.NewLogger()
_, myVpnNet, _ := net.ParseCIDR("10.128.0.1/16")
lh1 := "10.128.0.2"

c := config.NewC(l)
c.Settings["lighthouse"] = map[interface{}]interface{}{
"hosts": []interface{}{lh1},
"interval": "1s",
}

c.Settings["static_host_map"] = map[interface{}]interface{}{lh1: []interface{}{"1.1.1.1:4242"}}
lh, err := NewLightHouseFromConfig(context.Background(), l, c, myVpnNet, nil, nil)
assert.NoError(t, err)

mw := &mockEncWriter{}
origClosed := false
go func() {
lh.LhUpdateWorker(context.TODO(), mw)
origClosed = true
}()

c.ReloadConfigString("lighthouse.interval: 5s")
assert.True(t, origClosed)
}

func BenchmarkLighthouseHandleRequest(b *testing.B) {
l := test.NewLogger()
_, myVpnNet, _ := net.ParseCIDR("10.128.0.1/0")
Expand Down

0 comments on commit c9070e3

Please sign in to comment.