Fix Windows CI test failures (bd-99)

- Fix PID detection: Open lock file with O_RDWR for Windows LockFileEx
- Fix script tests: Increase timeout to 2-5s for Windows process startup
- Fix uptime test: Use math.Ceil with minimum 1 second to prevent flakiness
- Fix socket cleanup: Add done channel to wait for Start() cleanup completion

All 5 failing Windows tests should now pass.
This commit is contained in:
Steve Yegge
2025-10-24 10:07:05 -07:00
parent 58ea4548fa
commit 09e51b2184
5 changed files with 49 additions and 9 deletions

View File

@@ -62,6 +62,7 @@ type Server struct {
shutdown bool
shutdownChan chan struct{}
stopOnce sync.Once
doneChan chan struct{} // closed when Start() cleanup is complete
// Per-request storage routing with eviction support
storageCache map[string]*StorageCacheEntry // repoRoot -> entry
cacheMu sync.RWMutex
@@ -124,6 +125,7 @@ func NewServer(socketPath string, store storage.Storage) *Server {
maxCacheSize: maxCacheSize,
cacheTTL: cacheTTL,
shutdownChan: make(chan struct{}),
doneChan: make(chan struct{}),
startTime: time.Now(),
metrics: NewMetrics(),
maxConns: maxConns,
@@ -168,6 +170,9 @@ func (s *Server) Start(ctx context.Context) error {
go s.handleSignals()
go s.runCleanupLoop()
// Ensure cleanup is signaled when this function returns
defer close(s.doneChan)
// Accept connections using listener
for {
// Get listener under lock
@@ -254,6 +259,15 @@ func (s *Server) Stop() error {
err = fmt.Errorf("failed to remove socket: %w", removeErr)
}
})
// Wait for Start() goroutine to finish cleanup (with timeout)
select {
case <-s.doneChan:
// Cleanup completed
case <-time.After(2 * time.Second):
// Timeout waiting for cleanup - continue anyway
}
return err
}