@@ -29,7 +29,7 @@ use serde::Serializer;
29
29
use std:: process:: ExitStatus ;
30
30
use std:: { fmt, str:: FromStr , sync:: Arc } ;
31
31
#[ cfg( not( target_arch = "wasm32" ) ) ]
32
- use tokio:: process:: Child ;
32
+ use tokio:: { io :: Lines , process:: Child } ;
33
33
34
34
const ABSTRACTION_IDENTIFIER : HeaderName = HeaderName :: from_static ( "x-abstraction-identifier" ) ;
35
35
const RECORDING_ID : HeaderName = HeaderName :: from_static ( "x-recording-id" ) ;
@@ -76,36 +76,26 @@ impl Proxy {
76
76
)
77
77
} ) ?;
78
78
79
- let mut stdout = command
80
- . stdout
81
- . take ( )
82
- . ok_or_else ( || azure_core:: Error :: message ( ErrorKind :: Io , "no stdout pipe" ) ) ?;
83
- // Take stderr now but we won't listen until after start up, such that messages should buffer.
84
- let mut stderr = command
85
- . stderr
86
- . take ( )
87
- . ok_or_else ( || azure_core:: Error :: message ( ErrorKind :: Io , "no stderr pipe" ) ) ?;
79
+ let mut stdout = BufReader :: new (
80
+ command
81
+ . stdout
82
+ . take ( )
83
+ . ok_or_else ( || azure_core:: Error :: message ( ErrorKind :: Io , "no stdout pipe" ) ) ?,
84
+ )
85
+ . lines ( ) ;
88
86
self . command = Some ( command) ;
89
87
90
88
// Wait until the service is listening on a port.
91
89
self . wait_till_listening ( & mut stdout) . await ?;
92
90
93
- // Then spawn a thread to keep pumping messages to stdout and stderr .
91
+ // Then spawn a thread to keep pumping messages to stdout.
94
92
// The pipe will be closed when the process is shut down, which will terminate the task.
95
93
tokio:: spawn ( async move {
96
- let mut reader = BufReader :: new ( & mut stdout) . lines ( ) ;
97
- while let Some ( line) = reader. next_line ( ) . await . unwrap_or ( None ) {
94
+ while let Some ( line) = stdout. next_line ( ) . await . unwrap_or ( None ) {
98
95
// Trace useful lines that test-proxy writes to stdout.
99
96
trace_line ( Level :: TRACE , & line) ;
100
97
}
101
98
} ) ;
102
- tokio:: spawn ( async move {
103
- let mut reader = BufReader :: new ( & mut stderr) . lines ( ) ;
104
- while let Some ( line) = reader. next_line ( ) . await . unwrap_or ( None ) {
105
- // Trace useful lines that test-proxy writes to stdout.
106
- trace_line ( Level :: ERROR , & line) ;
107
- }
108
- } ) ;
109
99
110
100
if let Some ( endpoint) = & self . endpoint {
111
101
self . client = Some ( Client :: new ( endpoint. clone ( ) ) ?) ;
@@ -153,10 +143,12 @@ impl Proxy {
153
143
Ok ( ExitStatus :: default ( ) )
154
144
}
155
145
156
- async fn wait_till_listening ( & mut self , stdout : & mut ChildStdout ) -> Result < ( ) > {
146
+ async fn wait_till_listening (
147
+ & mut self ,
148
+ stdout : & mut Lines < BufReader < ChildStdout > > ,
149
+ ) -> Result < ( ) > {
157
150
let pid = self . command . as_ref ( ) . and_then ( Child :: id) ;
158
- let mut reader = BufReader :: new ( stdout) . lines ( ) ;
159
- while let Some ( line) = reader. next_line ( ) . await ? {
151
+ while let Some ( line) = stdout. next_line ( ) . await ? {
160
152
const RUNNING_PATTERN : & str = "Running proxy version is Azure.Sdk.Tools.TestProxy " ;
161
153
const LISTENING_PATTERN : & str = "Now listening on: " ;
162
154
0 commit comments