Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

56 rader
1.4 KiB

  1. // Copyright 2018, OpenCensus Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. package zpages
  16. import (
  17. "context"
  18. "testing"
  19. "time"
  20. "go.opencensus.io/internal/testpb"
  21. "go.opencensus.io/stats/view"
  22. )
  23. func TestRpcz(t *testing.T) {
  24. client, cleanup := testpb.NewTestClient(t)
  25. defer cleanup()
  26. _, err := client.Single(context.Background(), &testpb.FooRequest{})
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. view.SetReportingPeriod(time.Millisecond)
  31. time.Sleep(2 * time.Millisecond)
  32. view.SetReportingPeriod(time.Second)
  33. mu.Lock()
  34. defer mu.Unlock()
  35. if len(snaps) == 0 {
  36. t.Fatal("Expected len(snaps) > 0")
  37. }
  38. snapshot, ok := snaps[methodKey{"testpb.Foo/Single", false}]
  39. if !ok {
  40. t.Fatal("Expected method stats not recorded")
  41. }
  42. if got, want := snapshot.CountTotal, uint64(1); got != want {
  43. t.Errorf("snapshot.CountTotal = %d; want %d", got, want)
  44. }
  45. }