Skip to content

Commit 3d97dc3

Browse files
committed
clean up comments
1 parent 876d118 commit 3d97dc3

File tree

15 files changed

+30
-40
lines changed

15 files changed

+30
-40
lines changed

examples/composite/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func main() {
4747
os.Exit(1)
4848
}
4949

50-
// Simple config callback that randomizes intervals on reload
50+
// Config callback that randomizes intervals on reload
5151
configCallback := func() (*composite.Config[*Worker], error) {
5252
// Create entries array with our workers
5353
newEntries := make([]composite.RunnableEntry[*Worker], 2)

examples/composite/reload_membership_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestMembershipChangesBasic(t *testing.T) {
129129
{Runnable: worker2, Config: worker2.config},
130130
}
131131

132-
// Create simple config callback that always returns the current entries
132+
// Create config callback that returns the current entries
133133
configCh := make(chan []composite.RunnableEntry[*TestWorker], 1)
134134
configCh <- configEntries // Initial configuration
135135

examples/composite/worker_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@ func TestWorker_Execution_Timing(t *testing.T) {
384384
initialInterval,
385385
)
386386

387-
// Allow significant delta for scheduler jitter, GC, etc. (e.g., 60%)
387+
// Allow delta for scheduler jitter, GC, etc. (e.g., 60%)
388388
assert.InDelta(
389389
t,
390390
initialInterval.Seconds(),
391391
measuredInterval1.Seconds(),
392392
float64(initialInterval.Seconds())*0.6,
393-
"Measured average interval [%v] significantly different from initial interval [%v]",
393+
"Measured average interval [%v] different from initial interval [%v]",
394394
measuredInterval1,
395395
initialInterval,
396396
)
@@ -501,14 +501,9 @@ func TestWorker_ReloadWithConfig_Concurrency(t *testing.T) {
501501
finalConfig.Interval, readWorkerConfig(t, worker).Interval)
502502

503503
// Because ReloadWithConfig replaces the config in the channel if full,
504-
// we expect the *last* successfully queued config to eventually be applied.
505-
// This isn't strictly guaranteed to be `finalConfig` if the channel was full
506-
// and the last goroutine's send happened *before* an earlier one was processed,
507-
// but it's the most likely outcome.
508-
// A more robust check waits for the *interval* to match the final one,
509-
// as that's the primary observable effect managed by the Run loop.
510-
// Skip exact interval match check - the test is flaky because the last reload may not be the one processed
511-
// due to timing issues with 50 concurrent reloads
504+
// we cannot guarantee which config will be applied when running concurrent reloads.
505+
// The last goroutine's config might be replaced by an earlier one due to timing.
506+
// Skip exact interval match check due to this race condition with concurrent reloads
512507
t.Log("Skipping exact interval match check due to timing issues with concurrent reloads")
513508

514509
t.Logf(
@@ -702,4 +697,4 @@ func TestWorker_NewWorker_NilLogger(t *testing.T) {
702697

703698
// We'll remove TestWorker_StartTicker_ChannelFullWarning since it introduces
704699
// race conditions with the log buffer and it's difficult to test this edge case safely.
705-
// This test was trying to cover a simple warning log path which is not critical functionality.
700+
// This test was trying to cover a warning log path.

examples/http/main.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,14 @@ func RunServer(
107107
// Create a PIDZero supervisor and add the runner
108108
sv, err := supervisor.New(
109109
supervisor.WithContext(ctx),
110-
supervisor.WithRunnables(runner),
111-
supervisor.WithLogHandler(logHandler))
110+
supervisor.WithLogHandler(logHandler),
111+
supervisor.WithRunnables(runner))
112112
if err != nil {
113113
customCancel()
114114
return nil, nil, fmt.Errorf("failed to create supervisor: %w", err)
115115
}
116116

117-
// Create a cleanup function for proper teardown
118-
cleanup := func() {
119-
customCancel()
120-
}
121-
122-
return sv, cleanup, nil
117+
return sv, customCancel, nil
123118
}
124119

125120
func main() {
@@ -140,12 +135,12 @@ func main() {
140135
os.Exit(1)
141136
}
142137

143-
sv, cleanup, err := RunServer(ctx, handler, routes)
138+
sv, cancel, err := RunServer(ctx, handler, routes)
144139
if err != nil {
145140
slog.Error("Failed to setup server", "error", err)
146141
os.Exit(1)
147142
}
148-
defer cleanup()
143+
defer cancel()
149144

150145
// Start the supervisor - this will block until shutdown
151146
slog.Info("Starting supervisor with HTTP server on " + ListenOn)

runnables/composite/reload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ReloadableWithConfig interface {
1515

1616
// Reload updates the configuration and handles runnables appropriately.
1717
// If membership changes (different set of runnables), all existing runnables are stopped
18-
// and the new set is started to ensure proper lifecycle management.
18+
// and the new set of runnables is started.
1919
func (r *Runner[T]) Reload() {
2020
logger := r.logger.WithGroup("Reload")
2121
logger.Debug("Reloading...")

runnables/composite/reload_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestCompositeRunner_Reload(t *testing.T) {
240240
})
241241

242242
t.Run("reload with updated configurations", func(t *testing.T) {
243-
// Setup mock runnables with proper blocking behavior
243+
// Setup mock runnables with blocking behavior
244244
mockRunnable1 := mocks.NewMockRunnable()
245245
mockRunnable1.On("String").Return("runnable1").Maybe()
246246
mockRunnable1.On("Reload").Once()
@@ -371,7 +371,7 @@ func TestCompositeRunner_Reload(t *testing.T) {
371371
})
372372

373373
t.Run("reload with no config changes", func(t *testing.T) {
374-
// Setup mock runnables with proper blocking behavior
374+
// Setup mock runnables with blocking behavior
375375
mockRunnable1 := mocks.NewMockRunnable()
376376
mockRunnable1.On("String").Return("runnable1")
377377
mockRunnable1.On("Reload").Once()
@@ -495,7 +495,7 @@ func TestCompositeRunner_Reload(t *testing.T) {
495495
return NewConfig("test", initialEntries)
496496
}
497497

498-
// Create runner with proper context
498+
// Create runner with context
499499
ctx := t.Context()
500500
runner, err := NewRunner(
501501
configCallback,

runnables/httpcluster/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ func TestIntegration_IdenticalConfigPreservesServerInstance(t *testing.T) {
516516
currentRunner := currentEntry.runner
517517
runner.mu.RUnlock()
518518

519-
// This is the critical test: the runner instance should be the same
519+
// Verify the runner instance should be the same
520520
assert.Same(t, originalRunner, currentRunner,
521521
"Server instance should not have been recreated for identical config")
522522

runnables/httpcluster/runner_restart_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func TestPortBindingRaceCondition(t *testing.T) {
150150
t,
151151
numCycles,
152152
successCount,
153-
"All restarts should succeed with proper delay",
153+
"All restarts should succeed with delay",
154154
)
155155
} else {
156156
// With zero delay, we expect some failures due to port binding race
@@ -343,7 +343,7 @@ func TestConcurrentRestartStress(t *testing.T) {
343343
}, 5*time.Second, 10*time.Millisecond, "Both servers should be running after concurrent restarts")
344344
}
345345

346-
// BenchmarkServerRestarts measures performance of server restarts with proper delays
346+
// BenchmarkServerRestarts measures performance of server restarts with delays
347347
func BenchmarkServerRestarts(b *testing.B) {
348348
benchmarks := []struct {
349349
name string

runnables/httpserver/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/stretchr/testify/require"
1414
)
1515

16-
// Simple ResponseRecorder for testing
16+
// testResponseRecorder implements http.ResponseWriter for testing
1717
type testResponseRecorder struct {
1818
Headers http.Header
1919
Body []byte
@@ -160,7 +160,7 @@ func TestConfigEqual(t *testing.T) {
160160
func TestConfigGetMux(t *testing.T) {
161161
t.Parallel()
162162

163-
t.Run("Creates proper ServeMux", func(t *testing.T) {
163+
t.Run("Creates ServeMux", func(t *testing.T) {
164164
var handlerCalled bool
165165
handler := func(w http.ResponseWriter, r *http.Request) {
166166
handlerCalled = true

runnables/httpserver/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func WithConfigCallback(callback ConfigCallback) Option {
4141
}
4242

4343
// WithConfig sets the initial configuration for the Runner instance.
44-
// This option is a simple wrapper for the WithConfigCallback option, allowing you to pass a Config
44+
// This option wraps the WithConfigCallback option, allowing you to pass a Config
4545
// instance directly instead of a callback function. This is useful when you have a static
4646
// configuration that doesn't require dynamic loading or reloading.
4747
func WithConfig(cfg *Config) Option {

runnables/httpserver/reload_mocked_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (m *MockConfigCallback) Call() (*Config, error) {
2727
return args.Get(0).(*Config), args.Error(1)
2828
}
2929

30-
// Helper function to create a modified config
30+
// Helper function to create a modified Config with a single route
3131
func createModifiedConfigForMock(t *testing.T, addr string) *Config {
3232
t.Helper()
3333
routes := Routes{createTestRouteForMock(t, "/modified")}
@@ -36,7 +36,7 @@ func createModifiedConfigForMock(t *testing.T, addr string) *Config {
3636
return cfg
3737
}
3838

39-
// Helper function to create a simple test config
39+
// createSimpleConfigForMock creates a test Config with a single route
4040
func createSimpleConfigForMock(t *testing.T, addr string) *Config {
4141
t.Helper()
4242
routes := Routes{createTestRouteForMock(t, "/")}
@@ -45,7 +45,7 @@ func createSimpleConfigForMock(t *testing.T, addr string) *Config {
4545
return cfg
4646
}
4747

48-
// Helper function to create a test route
48+
// Helper function to create a test Route
4949
func createTestRouteForMock(t *testing.T, path string) Route {
5050
t.Helper()
5151
handler := func(w http.ResponseWriter, r *http.Request) {

runnables/httpserver/reload_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func TestReload(t *testing.T) {
324324
// This test is simplified to focus on the basic functionality
325325
// without relying on actual network connections
326326

327-
// Create a simple test server with a handler
327+
// Create a test server with a handler
328328
initialHandler := func(w http.ResponseWriter, r *http.Request) {
329329
w.WriteHeader(http.StatusOK)
330330
}

runnables/httpserver/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (r *Runner) boot() error {
293293
return fmt.Errorf("%w: %w", ErrServerBoot, err)
294294
}
295295

296-
// Get the actual listening address (especially important for auto-assigned ports)
296+
// Get the actual listening address for auto-assigned ports
297297
actualAddr := listenAddr
298298
r.serverMutex.RLock()
299299
if tcpAddr, ok := r.server.(interface{ Addr() net.Addr }); ok && tcpAddr.Addr() != nil {

runnables/httpserver/runner_shutdown_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func TestServerCleanupOnlyOnce(t *testing.T) {
171171

172172
// With the current implementation using a separate serverMutex,
173173
// both calls might succeed since we set server = nil outside sync.Once
174-
// The important thing to verify is that the shutdown was only called once
174+
// Verify that the shutdown was only called once
175175
for _, err := range errorResults {
176176
// Either err is nil or it's ErrServerNotRunning
177177
if err != nil {

supervisor/shutdown_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestPIDZero_StartShutdownManager_ContextCancel(t *testing.T) {
9999

100100
select {
101101
case <-waitChan:
102-
// WaitGroup finished cleanly, indicating proper cleanup
102+
// WaitGroup finished cleanly
103103
case <-time.After(1 * time.Second):
104104
t.Fatal("WaitGroup did not finish within the timeout after context cancellation")
105105
}

0 commit comments

Comments
 (0)