...

Source file src/go.opencensus.io/zpages/rpcz_test.go

Documentation: go.opencensus.io/zpages

     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  
    16  package zpages
    17  
    18  import (
    19  	"context"
    20  	"testing"
    21  	"time"
    22  
    23  	"go.opencensus.io/internal/testpb"
    24  	"go.opencensus.io/stats/view"
    25  )
    26  
    27  func TestRpcz(t *testing.T) {
    28  	client, cleanup := testpb.NewTestClient(t)
    29  	defer cleanup()
    30  
    31  	_, err := client.Single(context.Background(), &testpb.FooRequest{})
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  
    36  	view.SetReportingPeriod(time.Millisecond)
    37  	time.Sleep(2 * time.Millisecond)
    38  	view.SetReportingPeriod(time.Second)
    39  
    40  	mu.Lock()
    41  	defer mu.Unlock()
    42  
    43  	if len(snaps) == 0 {
    44  		t.Fatal("Expected len(snaps) > 0")
    45  	}
    46  
    47  	snapshot, ok := snaps[methodKey{"testpb.Foo/Single", false}]
    48  	if !ok {
    49  		t.Fatal("Expected method stats not recorded")
    50  	}
    51  
    52  	if got, want := snapshot.CountTotal, uint64(1); got != want {
    53  		t.Errorf("snapshot.CountTotal = %d; want %d", got, want)
    54  	}
    55  }
    56  

View as plain text