forked from marcboeker/go-duckdb
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathprofiling_test.go
More file actions
51 lines (39 loc) · 1.49 KB
/
profiling_test.go
File metadata and controls
51 lines (39 loc) · 1.49 KB
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
package duckdb
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestProfiling(t *testing.T) {
db := openDbWrapper(t, ``)
defer closeDbWrapper(t, db)
conn := openConnWrapper(t, db, context.Background())
defer closeConnWrapper(t, conn)
_, err := GetProfilingInfo(conn)
require.ErrorContains(t, err, errProfilingInfoEmpty.Error())
_, err = conn.ExecContext(context.Background(), `PRAGMA enable_profiling = 'no_output'`)
require.NoError(t, err)
_, err = conn.ExecContext(context.Background(), `PRAGMA profiling_mode = 'detailed'`)
require.NoError(t, err)
res, err := conn.QueryContext(context.Background(), `SELECT range AS i FROM range(100) ORDER BY i`)
require.NoError(t, err)
defer closeRowsWrapper(t, res)
info, err := GetProfilingInfo(conn)
require.NoError(t, err)
// 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")
_, err = conn.ExecContext(context.Background(), `PRAGMA disable_profiling`)
require.NoError(t, err)
info, err = GetProfilingInfo(conn)
require.ErrorContains(t, err, errProfilingInfoEmpty.Error())
}
func TestErrProfiling(t *testing.T) {
db := openDbWrapper(t, ``)
defer closeDbWrapper(t, db)
conn := openConnWrapper(t, db, context.Background())
defer closeConnWrapper(t, conn)
_, err := GetProfilingInfo(conn)
testError(t, err, errProfilingInfoEmpty.Error())
}