MCPcopy
hub / github.com/cloudflare/tableflip / TestFdsRemoveUnix

Function TestFdsRemoveUnix

fds_test.go:199–265  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

197}
198
199func TestFdsRemoveUnix(t *testing.T) {
200 socketPath, cleanup := tempSocket(t)
201 defer cleanup()
202
203 addrs := [][2]string{
204 {"unix", socketPath},
205 {"unixgram", socketPath + "Unixgram"},
206 }
207
208 if runtime.GOOS == "linux" {
209 addrs = append(addrs,
210 [2]string{"unixpacket", socketPath + "Unixpacket"},
211 )
212 }
213
214 makeFds := func(t *testing.T) *Fds {
215 fds := newFds(nil, nil)
216 for _, addr := range addrs {
217 var c io.Closer
218 var err error
219 if addr[0] == "unixgram" {
220 c, err = fds.ListenPacket(addr[0], addr[1])
221 } else {
222 c, err = fds.Listen(addr[0], addr[1])
223 }
224 if err != nil {
225 t.Fatalf("Can't listen on socket %v: %v", addr, err)
226 }
227 c.Close()
228 if _, err := os.Stat(addr[1]); err != nil {
229 t.Errorf("%s Close() unlinked socket: %s", addr[0], err)
230 }
231 }
232 return fds
233 }
234
235 t.Run("closeAndRemoveUsed", func(t *testing.T) {
236 parent := makeFds(t)
237 parent.closeAndRemoveUsed()
238 for _, addr := range addrs {
239 if _, err := os.Stat(addr[1]); err == nil {
240 t.Errorf("Used %s listeners are not removed", addr[0])
241 }
242 }
243 })
244
245 t.Run("closeInherited", func(t *testing.T) {
246 parent := makeFds(t)
247 child := newFds(parent.copy(), nil)
248 child.closeInherited()
249 for _, addr := range addrs {
250 if _, err := os.Stat(addr[1]); err == nil {
251 t.Errorf("Inherited but unused %s listeners are not removed", addr[0])
252 }
253 }
254 })
255
256 t.Run("closeUsed", func(t *testing.T) {

Callers

nothing calls this directly

Calls 8

tempSocketFunction · 0.85
newFdsFunction · 0.85
ListenPacketMethod · 0.80
closeAndRemoveUsedMethod · 0.80
copyMethod · 0.80
closeInheritedMethod · 0.80
closeUsedMethod · 0.80
ListenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…