blob: e73ccf6e33ecf0f9c4970a8697af95cf51fb017b [file] [log] [blame]
Hardik Windlass03fe56f2019-11-27 09:11:25 +00001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package model
17
18import (
19 "github.com/opencord/voltha-lib-go/v2/pkg/log"
20 "github.com/stretchr/testify/assert"
21 "reflect"
22 "testing"
23)
24
25func TestProfiling(t *testing.T) {
26 want := &profiling{}
27 result := GetProfiling()
28 if reflect.TypeOf(result) != reflect.TypeOf(want) {
29 t.Errorf("GetProfiling() = result: %v, want: %v", result, want)
30 }
31
32 /*
33 * GetProfiling() returns a singleton instance of the Profiling structure.
34 * Verifying this by interchangably calling other methods through above
35 * returned "result" instance and by again calling GetProfiling() method,
36 * and comparing the results, i.e. all are getting executed on the single
37 * same profiling instance.
38 */
39
40 log.Info("/***** Unit Test Begin: Profiling Report: *****/")
41 result.Report()
42
43 GetProfiling().AddToDatabaseRetrieveTime(2.0)
44 assert.Equal(t, 2.0, result.DatabaseRetrieveTime)
45 assert.Equal(t, 1, result.DatabaseRetrieveCount)
46 result.AddToDatabaseRetrieveTime(3.0)
47 assert.Equal(t, 5.0, GetProfiling().DatabaseRetrieveTime)
48 assert.Equal(t, 2, GetProfiling().DatabaseRetrieveCount)
49
50 GetProfiling().AddToInMemoryModelTime(2.0)
51 assert.Equal(t, 2.0, result.InMemoryModelTime)
52 assert.Equal(t, 1, result.InMemoryModelCount)
53 result.AddToInMemoryModelTime(3.0)
54 assert.Equal(t, 5.0, GetProfiling().InMemoryModelTime)
55 assert.Equal(t, 2, GetProfiling().InMemoryModelCount)
56
57 GetProfiling().AddToInMemoryProcessTime(2.0)
58 assert.Equal(t, 2.0, result.InMemoryProcessTime)
59 result.AddToInMemoryProcessTime(3.0)
60 assert.Equal(t, 5.0, GetProfiling().InMemoryProcessTime)
61
62 GetProfiling().AddToDatabaseStoreTime(2.0)
63 assert.Equal(t, 2.0, result.DatabaseStoreTime)
64 result.AddToDatabaseStoreTime(3.0)
65 assert.Equal(t, 5.0, GetProfiling().DatabaseStoreTime)
66
67 GetProfiling().AddToInMemoryLockTime(2.0)
68 assert.Equal(t, 2.0, result.InMemoryLockTime)
69 assert.Equal(t, 1, result.InMemoryLockCount)
70 result.AddToInMemoryLockTime(3.0)
71 assert.Equal(t, 5.0, GetProfiling().InMemoryLockTime)
72 assert.Equal(t, 2, GetProfiling().InMemoryLockCount)
73
74 log.Info("/***** Unit Test End: Profiling Report: *****/")
75 GetProfiling().Report()
76
77 result.Reset()
78}