FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ev-node/node/full_node_test.go at main · evstack/ev-node · GitHub
evstack
/
ev-node
Public
Notifications
You must be signed in to change notification settings
Fork
281
Star
361
Code
Issues
4
Pull requests
3
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ev-node
/
node
/
full_node_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
101 lines (86 loc) · 3.22 KB
Breadcrumbs
ev-node
/
node
/
full_node_test.go
Copy path
File metadata and controls
101 lines (86 loc) · 3.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//go:build !integration
package
node
import
(
"context"
"fmt"
"io"
"net/http"
"testing"
"time"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
raftpkg
"github.com/evstack/ev-node/pkg/raft"
"github.com/evstack/ev-node/pkg/service"
)
func
TestStartInstrumentationServer
(
t
*
testing.
T
) {
t
.
Parallel
()
require
:=
require
.
New
(
t
)
assert
:=
assert
.
New
(
t
)
var
config
=
getTestConfig
(
t
,
1
)
config
.
Instrumentation
.
Prometheus
=
true
config
.
Instrumentation
.
PrometheusListenAddr
=
"127.0.0.1:26660"
config
.
Instrumentation
.
Pprof
=
true
config
.
Instrumentation
.
PprofListenAddr
=
"127.0.0.1:26661"
node
:=
&
FullNode
{
nodeConfig
:
config
,
BaseService
:
*
service
.
NewBaseService
(
zerolog
.
Nop
(),
"TestNode"
,
nil
),
}
prometheusSrv
,
pprofSrv
:=
node
.
startInstrumentationServer
()
require
.
NotNil
(
prometheusSrv
,
"Prometheus server should be initialized"
)
require
.
NotNil
(
pprofSrv
,
"Pprof server should be initialized"
)
time
.
Sleep
(
100
*
time
.
Millisecond
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
fmt
.
Sprintf
(
"http://%s/metrics"
,
config
.
Instrumentation
.
PrometheusListenAddr
),
nil
)
require
.
NoError
(
err
,
"Failed to create Prometheus metrics request"
)
resp
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
//nolint:gosec // test-only request to local instrumentation endpoint
require
.
NoError
(
err
,
"Failed to get Prometheus metrics"
)
defer
func
() {
err
:=
resp
.
Body
.
Close
()
if
err
!=
nil
{
t
.
Logf
(
"Error closing response body: %v"
,
err
)
}
}()
assert
.
Equal
(
http
.
StatusOK
,
resp
.
StatusCode
,
"Prometheus metrics endpoint should return 200 OK"
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
require
.
NoError
(
err
)
assert
.
Contains
(
string
(
body
),
"# HELP"
,
"Prometheus metrics body should contain HELP lines"
)
req
,
err
=
http
.
NewRequest
(
http
.
MethodGet
,
fmt
.
Sprintf
(
"http://%s/debug/pprof/"
,
config
.
Instrumentation
.
PprofListenAddr
),
nil
)
require
.
NoError
(
err
,
"Failed to create pprof request"
)
resp
,
err
=
http
.
DefaultClient
.
Do
(
req
)
//nolint:gosec // test-only request to local instrumentation endpoint
require
.
NoError
(
err
,
"Failed to get Pprof index"
)
defer
func
() {
err
:=
resp
.
Body
.
Close
()
if
err
!=
nil
{
t
.
Logf
(
"Error closing response body: %v"
,
err
)
}
}()
assert
.
Equal
(
http
.
StatusOK
,
resp
.
StatusCode
,
"Pprof index endpoint should return 200 OK"
)
body
,
err
=
io
.
ReadAll
(
resp
.
Body
)
require
.
NoError
(
err
)
assert
.
Contains
(
string
(
body
),
"Types of profiles available"
,
"Pprof index body should contain expected text"
)
shutdownCtx
,
cancel
:=
context
.
WithTimeout
(
t
.
Context
(),
1
*
time
.
Second
)
defer
cancel
()
if
prometheusSrv
!=
nil
{
err
=
prometheusSrv
.
Shutdown
(
shutdownCtx
)
assert
.
NoError
(
err
,
"Prometheus server shutdown should not return error"
)
}
if
pprofSrv
!=
nil
{
err
=
pprofSrv
.
Shutdown
(
shutdownCtx
)
assert
.
NoError
(
err
,
"Pprof server shutdown should not return error"
)
}
}
func
TestFullNode_ResignLeader_Noop
(
t
*
testing.
T
) {
cases
:=
[]
struct
{
name
string
node
*
FullNode
}{
{
name
:
"nil raftNode"
,
node
:
&
FullNode
{}},
// Empty *raftpkg.Node has nil raft field so IsLeader() returns false.
{
name
:
"non-leader raftNode"
,
node
:
&
FullNode
{
raftNode
:
&
raftpkg.
Node
{}}},
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing.
T
) {
assert
.
NoError
(
t
,
tc
.
node
.
ResignLeader
(
context
.
Background
()))
})
}
}
Back
|
FazBrowse Home
|
New Git URL