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:
@@ -1,6 +1,7 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"math"
|
||||
"runtime"
|
||||
"sort"
|
||||
"sync"
|
||||
@@ -112,6 +113,12 @@ func (m *Metrics) Snapshot(cacheHits, cacheMisses int64, cacheSize, activeConns
|
||||
|
||||
// Compute statistics outside the lock
|
||||
uptime := time.Since(m.startTime)
|
||||
// Round up uptime and enforce minimum of 1 second if any time has passed
|
||||
// This prevents flaky tests on fast systems (especially Windows VMs)
|
||||
uptimeSeconds := math.Ceil(uptime.Seconds())
|
||||
if uptime > 0 && uptimeSeconds == 0 {
|
||||
uptimeSeconds = 1
|
||||
}
|
||||
|
||||
// Calculate per-operation stats
|
||||
operations := make([]OperationMetrics, 0, len(opsSet))
|
||||
@@ -152,7 +159,7 @@ func (m *Metrics) Snapshot(cacheHits, cacheMisses int64, cacheSize, activeConns
|
||||
|
||||
return MetricsSnapshot{
|
||||
Timestamp: time.Now(),
|
||||
UptimeSeconds: uptime.Seconds(),
|
||||
UptimeSeconds: uptimeSeconds,
|
||||
Operations: operations,
|
||||
CacheHits: cacheHits,
|
||||
CacheMisses: cacheMisses,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user