go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/aggrmetrics/pm_test.go (about)

     1  // Copyright 2021 The LUCI 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 aggrmetrics
    16  
    17  import (
    18  	"testing"
    19  
    20  	"google.golang.org/protobuf/types/known/timestamppb"
    21  
    22  	"go.chromium.org/luci/gae/service/datastore"
    23  
    24  	"go.chromium.org/luci/cv/internal/changelist"
    25  	"go.chromium.org/luci/cv/internal/cvtesting"
    26  	"go.chromium.org/luci/cv/internal/prjmanager"
    27  	"go.chromium.org/luci/cv/internal/prjmanager/prjpb"
    28  	"go.chromium.org/luci/cv/internal/run"
    29  
    30  	. "github.com/smartystreets/goconvey/convey"
    31  )
    32  
    33  func TestPMReporter(t *testing.T) {
    34  	t.Parallel()
    35  
    36  	Convey("pmReporter works", t, func() {
    37  		ct := cvtesting.Test{}
    38  		ctx, cancel := ct.SetUp(t)
    39  		defer cancel()
    40  
    41  		So(datastore.Put(ctx,
    42  			&prjmanager.Project{
    43  				ID:         "small",
    44  				EVersion:   1,
    45  				UpdateTime: ct.Clock.Now().UTC(),
    46  				State: &prjpb.PState{
    47  					Status: prjpb.Status_STARTED,
    48  					Pcls: []*prjpb.PCL{
    49  						{Clid: 1, Eversion: 1, Submitted: true},
    50  						{Clid: 2, Eversion: 2, Deps: []*changelist.Dep{{Clid: 1, Kind: changelist.DepKind_HARD}},
    51  							Triggers: &run.Triggers{CqVoteTrigger: &run.Trigger{Mode: "DryRun", Time: timestamppb.New(ct.Clock.Now())}},
    52  						},
    53  					},
    54  				},
    55  			},
    56  			&prjmanager.Project{
    57  				ID:         "empty",
    58  				EVersion:   1,
    59  				UpdateTime: ct.Clock.Now().UTC(),
    60  				State: &prjpb.PState{
    61  					Status: prjpb.Status_STARTED,
    62  				},
    63  			},
    64  		), ShouldBeNil)
    65  
    66  		r := pmReporter{}
    67  		So(r.report(ctx, []string{"small", "empty"}), ShouldBeNil)
    68  		So(ct.TSMonSentValue(ctx, metricPMEntitySize, "small"), ShouldBeBetween, 80, 90)
    69  		So(ct.TSMonSentValue(ctx, metricPMEntitySize, "empty"), ShouldBeBetween, 40, 50)
    70  	})
    71  }