File: pipelistener_test.go

package info (click to toggle)
golang-github-hugelgupf-socketpair 0.0~git20240723.9246f21-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 478 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package socketpair

import (
	"strings"
	"sync"
	"testing"
)

func TestListen(t *testing.T) {
	l := Listen()

	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()
		for {
			s, err := l.Accept()
			if err != nil {
				if !strings.Contains(err.Error(), "use of closed network connection") {
					t.Fatal(err)
				}
				return
			}

			s.Close()
		}
	}()
	defer wg.Wait()
	defer l.Close()

	client, err := l.Dial()
	if err != nil {
		t.Fatal(err)
	}
	client.Close()
}