MCPcopy
hub / github.com/gofiber/fiber / Test_Replace_ConcurrentAccess

Function Test_Replace_ConcurrentAccess

client/client_test.go:2051–2089  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2049}
2050
2051func Test_Replace_ConcurrentAccess(t *testing.T) {
2052 original := C()
2053 t.Cleanup(func() {
2054 defaultClient.Store(original)
2055 })
2056
2057 clients := []*Client{New(), New(), New()}
2058
2059 var nilLoads atomic.Int32
2060 var wg sync.WaitGroup
2061
2062 for i := range 4 {
2063 offset := i
2064 wg.Go(func() {
2065 for j := range 1_000 {
2066 restore := Replace(clients[(offset+j)%len(clients)])
2067 if C() == nil {
2068 nilLoads.Add(1)
2069 }
2070 restore()
2071 }
2072 })
2073 }
2074
2075 for range 4 {
2076 wg.Go(func() {
2077 for range 10_000 {
2078 if C() == nil {
2079 nilLoads.Add(1)
2080 }
2081 }
2082 })
2083 }
2084
2085 wg.Wait()
2086
2087 require.Zero(t, nilLoads.Load())
2088 require.NotNil(t, C())
2089}
2090
2091func Test_Set_Config_To_Request(t *testing.T) {
2092 t.Parallel()

Callers

nothing calls this directly

Calls 6

ReplaceFunction · 0.85
StoreMethod · 0.80
CFunction · 0.70
NewFunction · 0.70
AddMethod · 0.65
LoadMethod · 0.65

Tested by

no test coverage detected