This repository was archived by the owner on Jan 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmsearch_test.go
More file actions
63 lines (58 loc) · 1.41 KB
/
msearch_test.go
File metadata and controls
63 lines (58 loc) · 1.41 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2014 Mikio Hara. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ssdp
import (
"net/http"
"sync"
"testing"
"time"
)
func TestMSearch(t *testing.T) {
devln := Listener{}
dev, err := devln.ListenDevice(nil)
if err != nil {
t.Skip(err)
}
defer dev.Close()
devhdlr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
hdr := w.Header()
hdr.Set("Cache-Control", "max-age=1800")
hdr.Set("Location", "http://127.0.0.1:5963/dd.xml")
hdr.Set("BOOTID.UPNP.ORG", "1")
hdr.Set("Server", "Go ssdp package")
hdr.Set("USN", "uuid:--::run--")
w.Write(nil)
})
go dev.Serve(devhdlr)
cpln := Listener{LocalPort: "1901", MulticastLoopback: true}
cp, err := cpln.ListenControlPoint(nil)
if err != nil {
t.Fatal(err)
}
defer cp.Close()
cphdlr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
//t.Logf("CP: %+v, %+v", w, req)
})
go cp.Serve(cphdlr)
var wg sync.WaitGroup
const N = 3
wg.Add(N)
for i := 0; i < N; i++ {
go func() {
defer wg.Done()
hdr := make(http.Header)
hdr.Set("Test1", "oops:ouch-oops")
hdr.Set("Test2", "ouch:oops-ouch")
resps, err := cp.MSearch(hdr, nil, 300*time.Millisecond)
if err != nil {
t.Error(err)
}
t.Logf("%v responses received", len(resps))
for _, resp := range resps {
resp.Body.Close()
}
}()
}
wg.Wait()
}