forked from algorand/go-algorand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequestLogger_test.go
81 lines (71 loc) · 2.63 KB
/
requestLogger_test.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (C) 2019-2020 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.
package network
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/logging/telemetryspec"
)
type eventsDetailsLogger struct {
logging.Logger
eventReceived chan struct{}
}
func (dl eventsDetailsLogger) EventWithDetails(category telemetryspec.Category, identifier telemetryspec.Event, details interface{}) {
if category == telemetryspec.Network && identifier == telemetryspec.HTTPRequestEvent {
dl.eventReceived <- struct{}{}
}
}
// for two node network, check that B can ping A and get a reply
func TestRequestLogger(t *testing.T) {
log := logging.TestingLog(t)
dl := eventsDetailsLogger{Logger: log, eventReceived: make(chan struct{}, 1)}
log.SetLevel(logging.Level(defaultConfig.BaseLoggerDebugLevel))
netA := &WebsocketNetwork{
log: dl,
config: defaultConfig,
phonebook: MakePhonebook(1, 1*time.Millisecond),
GenesisID: "go-test-network-genesis",
NetworkID: config.Devtestnet,
}
netA.config.EnableRequestLogger = true
netA.setup()
netA.eventualReadyDelay = time.Second
netA.config.GossipFanout = 1
netA.Start()
defer func() { t.Log("stopping A"); netA.Stop(); t.Log("A done") }()
netB := makeTestWebsocketNode(t)
netB.config.GossipFanout = 1
addrA, postListen := netA.Address()
require.True(t, postListen)
t.Log(addrA)
netB.phonebook = MakePhonebook(1, 1*time.Millisecond)
netB.phonebook.ReplacePeerList([]string{addrA}, "default")
netB.Start()
defer func() { t.Log("stopping B"); netB.Stop(); t.Log("B done") }()
readyTimeout := time.NewTimer(2 * time.Second)
waitReady(t, netA, readyTimeout.C)
waitReady(t, netB, readyTimeout.C)
select {
case <-time.After(10 * time.Second):
// we failed to get the event within the time limits.
t.Errorf("Event was not written to logger")
case <-dl.eventReceived:
// great, we got the desired event!
}
}