@@ -9,10 +9,12 @@ import (
9
9
"net/http/httptest"
10
10
"net/url"
11
11
"testing"
12
+ "time"
12
13
13
14
"github.com/loadimpact/k6/lib"
14
15
"github.com/loadimpact/k6/stats"
15
16
"github.com/pkg/errors"
17
+ "github.com/sirupsen/logrus"
16
18
"github.com/stretchr/testify/assert"
17
19
"github.com/stretchr/testify/require"
18
20
)
@@ -139,6 +141,37 @@ func TestURL(t *testing.T) {
139
141
})
140
142
}
141
143
144
+ func TestMakeRequestTimeout (t * testing.T ) {
145
+ srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
146
+ time .Sleep (100 * time .Millisecond )
147
+ }))
148
+ defer srv .Close ()
149
+ ctx , cancel := context .WithCancel (context .Background ())
150
+ defer cancel ()
151
+ samples := make (chan stats.SampleContainer , 10 )
152
+ logger := logrus .New ()
153
+ logger .Level = logrus .DebugLevel
154
+ state := & lib.State {
155
+ Options : lib.Options {RunTags : & stats.SampleTags {}},
156
+ Transport : srv .Client ().Transport ,
157
+ Samples : samples ,
158
+ Logger : logger ,
159
+ }
160
+ ctx = lib .WithState (ctx , state )
161
+ req , _ := http .NewRequest ("GET" , srv .URL , nil )
162
+ var preq = & ParsedHTTPRequest {
163
+ Req : req ,
164
+ URL : & URL {u : req .URL },
165
+ Body : new (bytes.Buffer ),
166
+ Timeout : 10 * time .Millisecond ,
167
+ }
168
+
169
+ res , err := MakeRequest (ctx , preq )
170
+ require .NoError (t , err )
171
+ assert .NotNil (t , res )
172
+ assert .Len (t , samples , 1 )
173
+ }
174
+
142
175
func BenchmarkWrapDecompressionError (b * testing.B ) {
143
176
err := errors .New ("error" )
144
177
b .ResetTimer ()
0 commit comments