Enhance SteamCache shutdown and coalesced request handling
- Implemented a more robust shutdown mechanism using sync.Once to prevent multiple shutdown calls and ensure all background managers are stopped properly. - Refactored coalesced request handling to utilize atomic operations for waiting counts, improving thread safety and performance. - Introduced a done channel for coalesced requests to signal completion, enhancing the handling of concurrent requests and reducing potential deadlocks. - Updated logging to provide better insights into cache request processing and error handling.
This commit is contained in:
@@ -530,6 +530,18 @@ func newTestCacheWithFakeUpstream(t *testing.T, h http.HandlerFunc, mem, disk st
|
||||
t.Cleanup(s.Close)
|
||||
d := t.TempDir()
|
||||
sc := New("127.0.0.1:0", mem, disk, d, s.URL, "lru", "lru", 200, 10)
|
||||
t.Cleanup(func() {
|
||||
// timeout-wrapped + done sentinel so cleanup never hangs test (per requirements)
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
sc.Shutdown()
|
||||
close(done)
|
||||
}()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(2 * time.Second):
|
||||
}
|
||||
})
|
||||
return sc, s
|
||||
}
|
||||
func newCacheServer(t *testing.T, sc *SteamCache) *httptest.Server {
|
||||
@@ -540,7 +552,9 @@ func newCacheServer(t *testing.T, sc *SteamCache) *httptest.Server {
|
||||
}
|
||||
|
||||
func TestT2_ConcurrentStatEvictOpen(t *testing.T) {
|
||||
if testing.Short() { t.Skip() }
|
||||
if testing.Short() {
|
||||
t.Skip()
|
||||
}
|
||||
t.Parallel()
|
||||
f := func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200); w.Write(make([]byte, 128*1024)) }
|
||||
sc, _ := newTestCacheWithFakeUpstream(t, f, "512KB", "2MB") // pressure to evict
|
||||
|
||||
Reference in New Issue
Block a user