You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.2 KiB

  1. package view
  2. import (
  3. "context"
  4. "testing"
  5. "go.opencensus.io/stats"
  6. )
  7. func TestMeasureFloat64AndInt64(t *testing.T) {
  8. // Recording through both a Float64Measure and Int64Measure with the
  9. // same name should work.
  10. im := stats.Int64("TestMeasureFloat64AndInt64", "", stats.UnitDimensionless)
  11. fm := stats.Float64("TestMeasureFloat64AndInt64", "", stats.UnitDimensionless)
  12. if im == nil || fm == nil {
  13. t.Fatal("Error creating Measures")
  14. }
  15. v1 := &View{
  16. Name: "TestMeasureFloat64AndInt64/v1",
  17. Measure: im,
  18. Aggregation: Sum(),
  19. }
  20. v2 := &View{
  21. Name: "TestMeasureFloat64AndInt64/v2",
  22. Measure: fm,
  23. Aggregation: Sum(),
  24. }
  25. Register(v1, v2)
  26. stats.Record(context.Background(), im.M(5))
  27. stats.Record(context.Background(), fm.M(2.2))
  28. d1, _ := RetrieveData(v1.Name)
  29. d2, _ := RetrieveData(v2.Name)
  30. sum1 := d1[0].Data.(*SumData)
  31. sum2 := d2[0].Data.(*SumData)
  32. // We expect both views to return 7.2, as though we recorded on a single measure.
  33. if got, want := sum1.Value, 7.2; got != want {
  34. t.Errorf("sum1 = %v; want %v", got, want)
  35. }
  36. if got, want := sum2.Value, 7.2; got != want {
  37. t.Errorf("sum2 = %v; want %v", got, want)
  38. }
  39. }