-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruntime_test.go
118 lines (106 loc) · 2.4 KB
/
runtime_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
// please note that tRPC source code is licensed under the Apache 2.0 License,
// A copy of the Apache 2.0 License is included in this file.
//
//
package runtime_test
import (
"io"
"net"
"net/http"
"os"
"reflect"
r "runtime"
"strings"
"testing"
"time"
"trpc.group/trpc-go/trpc-go/errs"
runtime "trpc.group/trpc-go/trpc-metrics-runtime"
"github.com/agiledragon/gomonkey"
)
func TestRuntime(t *testing.T) {
patch2 := gomonkey.ApplyFunc(http.Post, func(url, contentType string,
body io.Reader) (resp *http.Response, err error) {
return &http.Response{Body: &net.TCPConn{}}, errs.New(1, "test")
})
defer patch2.Reset()
patch3 := gomonkey.ApplyFunc(os.Open, func(name string) (*os.File, error) {
return os.NewFile(uintptr(3), "test"), nil
})
defer patch3.Reset()
patch5 := gomonkey.ApplyFunc(strings.Split, func(s, sep string) []string {
return []string{"1", "2", "3"}
})
defer patch5.Reset()
mockRet := []gomonkey.OutputCell{
{
Values: gomonkey.Params{
1, nil,
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, nil,
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
}, {
Values: gomonkey.Params{
1, errs.New(1, "test"),
},
},
}
a := &os.File{}
patch4 := gomonkey.ApplyMethodSeq(reflect.TypeOf(a), "Read", mockRet)
defer patch4.Reset()
patch6 := gomonkey.ApplyFunc(r.ReadMemStats, func(m *r.MemStats) {
*m = r.MemStats{PauseNs: [256]uint64{1, 100e3, 500e3, 1e6, 10e6, 50e6, 100e6, 500e6, 1e9}}
})
defer patch6.Reset()
runtime.RuntimeMetrics()
time.Sleep(time.Second * 6)
}
func TestRuntime2(t *testing.T) {
runtime.RuntimeMetrics()
time.Sleep(time.Second * 6)
}