summaryrefslogtreecommitdiff
path: root/logging/telemetryspec/metric_test.go
blob: 0e096e72b03fd664eefb56b1d7d59a7b86c1053e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2019-2021 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

package telemetryspec

import (
	"encoding/json"
	"testing"
	"time"

	"github.com/algorand/go-algorand/test/partitiontest"
	"github.com/stretchr/testify/require"
)

func TestTransactionProcessingTimeDistibutionFormatting(t *testing.T) {
	partitiontest.PartitionTest(t)
	var processingTime transactionProcessingTimeDistibution
	processingTime.AddTransaction(50000 * time.Nanosecond)
	processingTime.AddTransaction(80000 * time.Nanosecond)
	processingTime.AddTransaction(120000 * time.Nanosecond)
	processingTime.AddTransaction(150000 * time.Nanosecond)
	processingTime.AddTransaction(180000 * time.Nanosecond)
	processingTime.AddTransaction(950000 * time.Nanosecond)
	processingTime.AddTransaction(2 * time.Millisecond)
	bytes, err := processingTime.MarshalJSON()
	require.NoError(t, err)
	require.Equal(t, []byte("[2,3,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]"), bytes)

	container := struct {
		ProcessingTime transactionProcessingTimeDistibution
	}{ProcessingTime: processingTime}

	bytes, err = json.Marshal(container)
	require.NoError(t, err)
	require.Equal(t, []byte("{\"ProcessingTime\":[2,3,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}"), bytes)
}