aqm_test.go 815 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package aqm
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "net/http"
  6. "sync"
  7. "sync/atomic"
  8. "testing"
  9. "time"
  10. "go-common/library/log"
  11. bm "go-common/library/net/http/blademaster"
  12. )
  13. func init() {
  14. log.Init(nil)
  15. }
  16. func TestAQM(t *testing.T) {
  17. var group sync.WaitGroup
  18. rand.Seed(time.Now().Unix())
  19. eng := bm.Default()
  20. router := eng.Use(New(nil).Limit())
  21. router.GET("/aqm", testaqm)
  22. go eng.Run(":9999")
  23. var errcount int64
  24. for i := 0; i < 100; i++ {
  25. group.Add(1)
  26. go func() {
  27. defer group.Done()
  28. for j := 0; j < 300; j++ {
  29. _, err := http.Get("http://127.0.0.1:9999/aqm")
  30. if err != nil {
  31. atomic.AddInt64(&errcount, 1)
  32. }
  33. }
  34. }()
  35. }
  36. group.Wait()
  37. fmt.Println("errcount", errcount)
  38. }
  39. func testaqm(ctx *bm.Context) {
  40. count := rand.Intn(100)
  41. time.Sleep(time.Millisecond * time.Duration(count))
  42. }