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 pathnotify_test.go
More file actions
63 lines (58 loc) · 1.31 KB
/
notify_test.go
File metadata and controls
63 lines (58 loc) · 1.31 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 TestNotify(t *testing.T) {
devln := Listener{LocalPort: "1901", MulticastLoopback: true}
dev, err := devln.ListenDevice(nil)
if err != nil {
t.Skip(err)
}
defer dev.Close()
devhdlr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
//t.Logf("DEV: %+v, %+v", w, req)
})
go dev.Serve(devhdlr)
cpln := Listener{}
cp, err := cpln.ListenControlPoint(nil)
if err != nil {
t.Fatal(err)
}
defer cp.Close()
var rcvd = struct {
sync.RWMutex
reqs []*http.Request
}{}
cphdlr := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
//t.Logf("CP: %+v, %+v", w, req)
rcvd.Lock()
rcvd.reqs = append(rcvd.reqs, req)
rcvd.Unlock()
})
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")
if err := dev.Notify(hdr, nil); err != nil {
t.Error(err)
}
}()
}
wg.Wait()
time.Sleep(2 * time.Second)
rcvd.RLock()
t.Logf("%v requests received", len(rcvd.reqs))
rcvd.RUnlock()
}