MCPcopy
hub / github.com/WireGuard/wireguard-go / TestUpDown

Function TestUpDown

device/device_test.go:206–241  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

204}
205
206func TestUpDown(t *testing.T) {
207 goroutineLeakCheck(t)
208 const itrials = 50
209 const otrials = 10
210
211 for n := 0; n < otrials; n++ {
212 pair := genTestPair(t, false)
213 for i := range pair {
214 for k := range pair[i].dev.peers.keyMap {
215 pair[i].dev.IpcSet(fmt.Sprintf("public_key=%s\npersistent_keepalive_interval=1\n", hex.EncodeToString(k[:])))
216 }
217 }
218 var wg sync.WaitGroup
219 wg.Add(len(pair))
220 for i := range pair {
221 go func(d *Device) {
222 defer wg.Done()
223 for i := 0; i < itrials; i++ {
224 if err := d.Up(); err != nil {
225 t.Errorf("failed up bring up device: %v", err)
226 }
227 time.Sleep(time.Duration(rand.Intn(int(time.Nanosecond * (0x10000 - 1)))))
228 if err := d.Down(); err != nil {
229 t.Errorf("failed to bring down device: %v", err)
230 }
231 time.Sleep(time.Duration(rand.Intn(int(time.Nanosecond * (0x10000 - 1)))))
232 }
233 }(pair[i].dev)
234 }
235 wg.Wait()
236 for i := range pair {
237 pair[i].dev.Up()
238 pair[i].dev.Close()
239 }
240 }
241}
242
243// TestConcurrencySafety does other things concurrently with tunnel use.
244// It is intended to be used with the race detector to catch data races.

Callers

nothing calls this directly

Calls 7

goroutineLeakCheckFunction · 0.85
genTestPairFunction · 0.85
IpcSetMethod · 0.80
UpMethod · 0.80
DownMethod · 0.80
WaitMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected