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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package newrelic
import (
"errors"
"fmt"
"testing"
"time"
)
func TestConnectBackoff(t *testing.T) {
attempts := map[int]int{
0: 15,
2: 30,
5: 300,
6: 300,
100: 300,
-5: 300,
}
for k, v := range attempts {
if b := getConnectBackoffTime(k); b != v {
t.Error(fmt.Sprintf("Invalid connect backoff for attempt #%d:", k), v)
}
}
}
func TestNilApplication(t *testing.T) {
var app *Application
if txn := app.StartTransaction("name"); txn != nil {
t.Error(txn)
}
app.RecordCustomEvent("myEventType", map[string]interface{}{"zip": "zap"})
app.RecordCustomMetric("myMetric", 123.45)
if err := app.WaitForConnection(2 * time.Second); nil != err {
t.Error(err)
}
app.Shutdown(2 * time.Second)
}
func TestEmptyApplication(t *testing.T) {
app := &Application{}
if txn := app.StartTransaction("name"); txn != nil {
t.Error(txn)
}
app.RecordCustomEvent("myEventType", map[string]interface{}{"zip": "zap"})
app.RecordCustomMetric("myMetric", 123.45)
if err := app.WaitForConnection(2 * time.Second); nil != err {
t.Error(err)
}
app.Shutdown(2 * time.Second)
}
func TestConfigOptionError(t *testing.T) {
err := errors.New("myError")
app, got := NewApplication(
nil, // nil config options should be ignored
func(cfg *Config) {
cfg.Error = err
},
func(cfg *Config) {
t.Fatal("this config option should not be run")
},
)
if err != got {
t.Error("config option not returned", err, got)
}
if app != nil {
t.Error("app not nil")
}
}
|