@@ -4,6 +4,9 @@ package xmlrpc
4
4
5
5
import (
6
6
"context"
7
+ "io"
8
+ "net/http"
9
+ "net/http/httptest"
7
10
"runtime"
8
11
"sync"
9
12
"testing"
@@ -131,11 +134,54 @@ func Test_CloseMemoryLeak(t *testing.T) {
131
134
}
132
135
}
133
136
137
+ func Test_BadStatus (t * testing.T ) {
138
+
139
+ // this is a mock xmlrpc server which sends an invalid status code on the first request
140
+ // and an empty methodResponse for all subsequence requests
141
+ first := true
142
+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
143
+ if first {
144
+ first = false
145
+ http .Error (w , "bad status" , http .StatusInternalServerError )
146
+ } else {
147
+ io .WriteString (w , `
148
+ <?xml version="1.0" encoding="UTF-8"?>
149
+ <methodResponse>
150
+ <params>
151
+ <param>
152
+ <value>
153
+ <struct></struct>
154
+ </value>
155
+ </param>
156
+ </params>
157
+ </methodResponse>
158
+ ` )
159
+ }
160
+ }))
161
+
162
+ client , err := NewClient (ts .URL , nil )
163
+ if err != nil {
164
+ t .Fatalf ("Can't create client: %v" , err )
165
+ }
166
+ defer client .Close ()
167
+
168
+ var result interface {}
169
+
170
+ // expect an error due to the bad status code
171
+ if err := client .Call ("method" , nil , & result ); err == nil {
172
+ t .Fatalf ("Bad status didn't result in error" )
173
+ }
174
+
175
+ // expect subsequent calls to succeed
176
+ if err := client .Call ("method" , nil , & result ); err != nil {
177
+ t .Fatalf ("Failed to recover after bad status: %v" , err )
178
+ }
179
+ }
180
+
134
181
func newClient (t * testing.T ) * Client {
135
182
client , err := NewClient ("http://localhost:5001" , nil )
136
183
if err != nil {
137
184
t .Fatalf ("Can't create client: %v" , err )
138
185
}
139
-
140
186
return client
141
187
}
0 commit comments