HTTP load generator, ApacheBench (ab) replacement
Go
Adding tests for number of requests and rate limiting.
Burcu Dogan55d25c994014
diff --git a/commands/run_test.go b/commands/run_test.gonew file mode 100644index 0000000..cab1416--- /dev/null+++ b/commands/run_test.go@@ -0,0 +1,71 @@+// Copyright 2014 Google Inc. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package commands++import (+ "net/http"+ "net/http/httptest"+ "sync"+ "sync/atomic"+ "testing"+ "time"+)++func TestN(t *testing.T) {+ var count int64+ handler := func(w http.ResponseWriter, r *http.Request) {+ atomic.AddInt64(&count, int64(1))+ }+ server := httptest.NewServer(http.HandlerFunc(handler))+ defer server.Close()++ req, _ := http.NewRequest("GET", server.URL, nil)+ boom := &Boom{+ Req: req,+ N: 20,+ C: 2,+ }+ boom.Run()+ if count != 20 {+ t.Errorf("Expected to boom 20 times, found %v", count)+ }+}++func TestQps(t *testing.T) {+ var wg sync.WaitGroup+ var count int64+ handler := func(w http.ResponseWriter, r *http.Request) {+ atomic.AddInt64(&count, int64(1))+ }+ server := httptest.NewServer(http.HandlerFunc(handler))+ defer server.Close()++ req, _ := http.NewRequest("GET", server.URL, nil)+ boom := &Boom{+ Req: req,+ N: 20,+ C: 2,+ Qps: 1,+ }+ wg.Add(1)+ time.AfterFunc(time.Second, func() {+ if count > 1 {+ t.Errorf("Expected to boom 1 times, found %v", count)+ }+ wg.Done()+ })+ go boom.Run()+ wg.Wait()+}