MCPcopy Create free account
hub / github.com/SamNet-dev/snix / TestProbeSNIsConcurrent

Function TestProbeSNIsConcurrent

scanner/sni_test.go:107–135  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

105}
106
107func TestProbeSNIsConcurrent(t *testing.T) {
108 addr, stop := tlsTestServer(t)
109 defer stop()
110 ip, port := hostPort(t, addr)
111
112 in := []string{"a.com", "b.com", "c.com", "d.com", "e.com"}
113 // onResult may fire from multiple goroutines — caller is responsible
114 // for synchronising. Using atomic to keep the race detector happy.
115 var resultsSeen atomic.Int64
116 results := ProbeSNIs(context.Background(), in, ProbeConfig{
117 TargetIP: ip,
118 TargetPort: port,
119 Concurrency: 2,
120 }, func(Result) { resultsSeen.Add(1) })
121 if len(results) != len(in) {
122 t.Fatalf("len: %d want %d", len(results), len(in))
123 }
124 if int(resultsSeen.Load()) != len(in) {
125 t.Errorf("onResult callback count: %d want %d", resultsSeen.Load(), len(in))
126 }
127 for i, r := range results {
128 if r.SNI != in[i] {
129 t.Errorf("order not preserved: [%d] %s != %s", i, r.SNI, in[i])
130 }
131 if r.Outcome != OutcomeOK {
132 t.Errorf("%s: outcome %s err=%q", r.SNI, r.Outcome, r.Err)
133 }
134 }
135}
136
137func TestRankSNIsKeepsOnlyOK(t *testing.T) {
138 in := []Result{

Callers

nothing calls this directly

Calls 4

tlsTestServerFunction · 0.85
hostPortFunction · 0.85
ProbeSNIsFunction · 0.85
AddMethod · 0.80

Tested by

no test coverage detected