16
16
package monitor_test
17
17
18
18
import (
19
+ "bytes"
19
20
"context"
20
21
"errors"
21
22
"fmt"
@@ -60,6 +61,7 @@ func TestMonitorGRPCClose(t *testing.T) {
60
61
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 3 )
61
62
mon , err := grpcInst .Monitor (ctx , ports [0 ].GetPort ())
62
63
var tmpFile * paths.Path
64
+ fullRx := bytes .NewBuffer (nil )
63
65
for {
64
66
monResp , err := mon .Recv ()
65
67
if err != nil {
@@ -68,9 +70,11 @@ func TestMonitorGRPCClose(t *testing.T) {
68
70
}
69
71
fmt .Printf ("MON> %v\n " , monResp )
70
72
if rx := monResp .GetRxData (); rx != nil {
71
- if matches := tmpFileMatcher .FindAllStringSubmatch (string (rx ), - 1 ); len (matches ) > 0 {
73
+ fullRx .Write (rx )
74
+ if matches := tmpFileMatcher .FindAllStringSubmatch (fullRx .String (), - 1 ); len (matches ) > 0 {
72
75
fmt .Println ("Found tmpFile" , matches [0 ][1 ])
73
76
tmpFile = paths .New (matches [0 ][1 ])
77
+ fullRx .Reset ()
74
78
}
75
79
}
76
80
}
@@ -87,6 +91,7 @@ func TestMonitorGRPCClose(t *testing.T) {
87
91
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
88
92
mon , err := grpcInst .Monitor (ctx , ports [0 ].GetPort ())
89
93
var tmpFile * paths.Path
94
+ fullRx := bytes .NewBuffer (nil )
90
95
for {
91
96
monResp , err := mon .Recv ()
92
97
if errors .Is (err , io .EOF ) {
@@ -97,13 +102,16 @@ func TestMonitorGRPCClose(t *testing.T) {
97
102
require .NoError (t , err )
98
103
fmt .Printf ("MON> %v\n " , monResp )
99
104
if rx := monResp .GetRxData (); rx != nil {
100
- if matches := tmpFileMatcher .FindAllStringSubmatch (string (rx ), - 1 ); len (matches ) > 0 {
105
+ fullRx .Write (rx )
106
+ if matches := tmpFileMatcher .FindAllStringSubmatch (fullRx .String (), - 1 ); len (matches ) > 0 {
101
107
fmt .Println ("Found tmpFile" , matches [0 ][1 ])
102
108
tmpFile = paths .New (matches [0 ][1 ])
109
+ fullRx .Reset ()
103
110
go func () {
104
111
time .Sleep (time .Second )
105
112
fmt .Println ("<MON Sent close command" )
106
- mon .Send (& commands.MonitorRequest {Message : & commands.MonitorRequest_Close {Close : true }})
113
+ err := mon .Send (& commands.MonitorRequest {Message : & commands.MonitorRequest_Close {Close : true }})
114
+ require .NoError (t , err )
107
115
}()
108
116
}
109
117
}
0 commit comments