forked from snowflakedb/gosnowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heartbeat_test.go
64 lines (55 loc) · 2 KB
/
heartbeat_test.go
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
// Copyright (c) 2023 Snowflake Computing Inc. All rights reserved.
package gosnowflake
import (
"context"
"testing"
)
func TestUnitPostHeartbeat(t *testing.T) {
runSnowflakeConnTest(t, func(sct *SCTest) {
// send heartbeat call and renew expired session
sr := &snowflakeRestful{
FuncPost: postTestRenew,
FuncRenewSession: renewSessionTest,
TokenAccessor: getSimpleTokenAccessor(),
RequestTimeout: 0,
}
heartbeat := &heartbeat{
restful: sr,
}
err := heartbeat.heartbeatMain()
assertNilF(t, err, "failed to heartbeat and renew session")
heartbeat.restful.FuncPost = postTestError
err = heartbeat.heartbeatMain()
assertNotNilF(t, err, "should have failed to start heartbeat")
assertEqualE(t, err.Error(), "failed to run post method")
heartbeat.restful.FuncPost = postTestSuccessButInvalidJSON
err = heartbeat.heartbeatMain()
assertNotNilF(t, err, "should have failed to start heartbeat")
assertHasPrefixE(t, err.Error(), "invalid character")
heartbeat.restful.FuncPost = postTestAppForbiddenError
err = heartbeat.heartbeatMain()
assertNotNilF(t, err, "should have failed to start heartbeat")
driverErr, ok := err.(*SnowflakeError)
assertTrueF(t, ok, "connection should be snowflakeConn")
assertEqualE(t, driverErr.Number, ErrFailedToHeartbeat)
})
}
func TestHeartbeatStartAndStop(t *testing.T) {
createDSNWithClientSessionKeepAlive()
config, err := ParseDSN(dsn)
if err != nil {
t.Fatalf("failed to parse dsn. err: %v", err)
}
driver := SnowflakeDriver{}
db, err := driver.OpenWithConfig(context.Background(), *config)
if err != nil {
t.Fatalf("failed to open with config. config: %v, err: %v", config, err)
}
conn, ok := db.(*snowflakeConn)
assertTrueF(t, ok, "connection should be snowflakeConn")
assertNotNilF(t, conn.rest, "heartbeat should not be nil")
assertNotNilF(t, conn.rest.HeartBeat, "heartbeat should not be nil")
err = db.Close()
assertNilF(t, err, "should not cause error in Close")
assertNilF(t, conn.rest, "heartbeat should be nil")
}