forked from marcboeker/go-duckdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiling_test.go
52 lines (42 loc) · 1.43 KB
/
profiling_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
package duckdb
import (
"context"
"database/sql"
"testing"
"github.com/stretchr/testify/require"
)
func TestProfiling(t *testing.T) {
t.Parallel()
db, err := sql.Open("duckdb", "")
require.NoError(t, err)
con, err := db.Conn(context.Background())
require.NoError(t, err)
_, err = con.ExecContext(context.Background(), `PRAGMA enable_profiling = 'no_output'`)
require.NoError(t, err)
_, err = con.ExecContext(context.Background(), `PRAGMA profiling_mode = 'detailed'`)
require.NoError(t, err)
res, err := con.QueryContext(context.Background(), `SELECT range AS i FROM range(100) ORDER BY i`)
require.NoError(t, err)
info, err := GetProfilingInfo(con)
require.NoError(t, err)
_, err = con.ExecContext(context.Background(), `PRAGMA disable_profiling`)
require.NoError(t, err)
require.NoError(t, res.Close())
require.NoError(t, con.Close())
require.NoError(t, db.Close())
// Verify the metrics.
require.NotEmpty(t, info.Metrics, "metrics must not be empty")
require.NotEmpty(t, info.Children, "children must not be empty")
require.NotEmpty(t, info.Children[0].Metrics, "child metrics must not be empty")
}
func TestErrProfiling(t *testing.T) {
t.Parallel()
db, err := sql.Open("duckdb", "")
require.NoError(t, err)
con, err := db.Conn(context.Background())
require.NoError(t, err)
_, err = GetProfilingInfo(con)
testError(t, err, errProfilingInfoEmpty.Error())
require.NoError(t, con.Close())
require.NoError(t, db.Close())
}