influxdb/notebooks/service_test.go

206 lines
5.3 KiB
Go
Raw Normal View History

package notebooks
import (
"context"
"fmt"
"testing"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/snowflake"
"github.com/influxdata/influxdb/v2/sqlite"
"github.com/influxdata/influxdb/v2/sqlite/migrations"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
var (
idGen = snowflake.NewIDGenerator()
)
func TestCreateAndGetNotebook(t *testing.T) {
t.Parallel()
test: use `T.TempDir` to create temporary test directory (#23258) * test: use `T.TempDir` to create temporary test directory This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `os.MkdirTemp` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestSendWrite on Windows === FAIL: replications/internal TestSendWrite (0.29s) logger.go:130: 2022-06-23T13:00:54.290Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestSendWrite1627281409\\001\\replicationq\\0000000000000001"} logger.go:130: 2022-06-23T13:00:54.457Z ERROR Error in replication stream {"replication_id": "0000000000000001", "error": "remote timeout", "retries": 1} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestSendWrite1627281409\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestStore_BadShard on Windows === FAIL: tsdb TestStore_BadShard (0.09s) logger.go:130: 2022-06-23T12:18:21.827Z INFO Using data dir {"service": "store", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestStore_BadShard1363295568\\001"} logger.go:130: 2022-06-23T12:18:21.827Z INFO Compaction settings {"service": "store", "max_concurrent_compactions": 2, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (start) {"service": "store", "op_name": "tsdb_open", "op_event": "start"} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (end) {"service": "store", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "77.3µs"} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestStore_BadShard1363295568\002\data\db0\rp0\1\index\0\L0-00000001.tsl: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestPartition_PrependLogFile_Write_Fail and TestPartition_Compact_Write_Fail on Windows === FAIL: tsdb/index/tsi1 TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_PrependLogFile_Write_Failwrite_MANIFEST656030081\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) === FAIL: tsdb/index/tsi1 TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_Compact_Write_Failwrite_MANIFEST3398667527\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) We must close the open file descriptor otherwise the temporary file cannot be cleaned up on Windows. Fixes: 619eb1cae6 ("fix: restore in-memory Manifest on write error") Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestReplicationStartMissingQueue on Windows === FAIL: TestReplicationStartMissingQueue (1.60s) logger.go:130: 2023-03-17T10:42:07.269Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} logger.go:130: 2023-03-17T10:42:07.305Z INFO Opened replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestReplicationStartMissingQueue76668607\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: update TestWAL_DiskSize Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestWAL_DiskSize on Windows === FAIL: tsdb/engine/tsm1 TestWAL_DiskSize (2.65s) testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestWAL_DiskSize2736073801\001\_00006.wal: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> --------- Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-03-21 20:22:11 +00:00
svc := newTestService(t)
ctx := context.Background()
// getting an invalid id should return an error
got, err := svc.GetNotebook(ctx, idGen.ID())
require.Nil(t, got)
require.ErrorIs(t, influxdb.ErrNotebookNotFound, err)
testCreate := &influxdb.NotebookReqBody{
OrgID: idGen.ID(),
Name: "some name",
Spec: map[string]interface{}{"hello": "goodbye"},
}
// create a notebook and assert the results
gotCreate, err := svc.CreateNotebook(ctx, testCreate)
require.NoError(t, err)
gotCreateBody := &influxdb.NotebookReqBody{
OrgID: gotCreate.OrgID,
Name: gotCreate.Name,
Spec: gotCreate.Spec,
}
require.Equal(t, testCreate, gotCreateBody)
// get the notebook with the ID that was created and assert the results
gotGet, err := svc.GetNotebook(ctx, gotCreate.ID)
require.NoError(t, err)
gotGetBody := &influxdb.NotebookReqBody{
OrgID: gotGet.OrgID,
Name: gotGet.Name,
Spec: gotGet.Spec,
}
require.Equal(t, testCreate, gotGetBody)
}
func TestUpdate(t *testing.T) {
t.Parallel()
test: use `T.TempDir` to create temporary test directory (#23258) * test: use `T.TempDir` to create temporary test directory This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `os.MkdirTemp` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestSendWrite on Windows === FAIL: replications/internal TestSendWrite (0.29s) logger.go:130: 2022-06-23T13:00:54.290Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestSendWrite1627281409\\001\\replicationq\\0000000000000001"} logger.go:130: 2022-06-23T13:00:54.457Z ERROR Error in replication stream {"replication_id": "0000000000000001", "error": "remote timeout", "retries": 1} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestSendWrite1627281409\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestStore_BadShard on Windows === FAIL: tsdb TestStore_BadShard (0.09s) logger.go:130: 2022-06-23T12:18:21.827Z INFO Using data dir {"service": "store", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestStore_BadShard1363295568\\001"} logger.go:130: 2022-06-23T12:18:21.827Z INFO Compaction settings {"service": "store", "max_concurrent_compactions": 2, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (start) {"service": "store", "op_name": "tsdb_open", "op_event": "start"} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (end) {"service": "store", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "77.3µs"} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestStore_BadShard1363295568\002\data\db0\rp0\1\index\0\L0-00000001.tsl: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestPartition_PrependLogFile_Write_Fail and TestPartition_Compact_Write_Fail on Windows === FAIL: tsdb/index/tsi1 TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_PrependLogFile_Write_Failwrite_MANIFEST656030081\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) === FAIL: tsdb/index/tsi1 TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_Compact_Write_Failwrite_MANIFEST3398667527\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) We must close the open file descriptor otherwise the temporary file cannot be cleaned up on Windows. Fixes: 619eb1cae6 ("fix: restore in-memory Manifest on write error") Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestReplicationStartMissingQueue on Windows === FAIL: TestReplicationStartMissingQueue (1.60s) logger.go:130: 2023-03-17T10:42:07.269Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} logger.go:130: 2023-03-17T10:42:07.305Z INFO Opened replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestReplicationStartMissingQueue76668607\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: update TestWAL_DiskSize Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestWAL_DiskSize on Windows === FAIL: tsdb/engine/tsm1 TestWAL_DiskSize (2.65s) testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestWAL_DiskSize2736073801\001\_00006.wal: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> --------- Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-03-21 20:22:11 +00:00
svc := newTestService(t)
ctx := context.Background()
testCreate := &influxdb.NotebookReqBody{
OrgID: idGen.ID(),
Name: "some name",
Spec: map[string]interface{}{"hello": "goodbye"},
}
testUpdate := &influxdb.NotebookReqBody{
OrgID: testCreate.OrgID,
Name: "a new name",
Spec: map[string]interface{}{"aloha": "aloha"},
}
// attempting to update a non-existant notebook should return an error
got, err := svc.UpdateNotebook(ctx, idGen.ID(), testUpdate)
require.Nil(t, got)
require.ErrorIs(t, influxdb.ErrNotebookNotFound, err)
// create the notebook so updating it can be tested
gotCreate, err := svc.CreateNotebook(ctx, testCreate)
require.NoError(t, err)
gotCreateBody := &influxdb.NotebookReqBody{
OrgID: gotCreate.OrgID,
Name: gotCreate.Name,
Spec: gotCreate.Spec,
}
require.Equal(t, testCreate, gotCreateBody)
// try to update the notebook and assert the results
gotUpdate, err := svc.UpdateNotebook(ctx, gotCreate.ID, testUpdate)
require.NoError(t, err)
gotUpdateBody := &influxdb.NotebookReqBody{
OrgID: gotUpdate.OrgID,
Name: gotUpdate.Name,
Spec: gotUpdate.Spec,
}
require.Equal(t, testUpdate, gotUpdateBody)
require.Equal(t, gotCreate.ID, gotUpdate.ID)
require.Equal(t, gotCreate.CreatedAt, gotUpdate.CreatedAt)
require.NotEqual(t, gotUpdate.CreatedAt, gotUpdate.UpdatedAt)
}
func TestDelete(t *testing.T) {
t.Parallel()
test: use `T.TempDir` to create temporary test directory (#23258) * test: use `T.TempDir` to create temporary test directory This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `os.MkdirTemp` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestSendWrite on Windows === FAIL: replications/internal TestSendWrite (0.29s) logger.go:130: 2022-06-23T13:00:54.290Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestSendWrite1627281409\\001\\replicationq\\0000000000000001"} logger.go:130: 2022-06-23T13:00:54.457Z ERROR Error in replication stream {"replication_id": "0000000000000001", "error": "remote timeout", "retries": 1} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestSendWrite1627281409\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestStore_BadShard on Windows === FAIL: tsdb TestStore_BadShard (0.09s) logger.go:130: 2022-06-23T12:18:21.827Z INFO Using data dir {"service": "store", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestStore_BadShard1363295568\\001"} logger.go:130: 2022-06-23T12:18:21.827Z INFO Compaction settings {"service": "store", "max_concurrent_compactions": 2, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (start) {"service": "store", "op_name": "tsdb_open", "op_event": "start"} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (end) {"service": "store", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "77.3µs"} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestStore_BadShard1363295568\002\data\db0\rp0\1\index\0\L0-00000001.tsl: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestPartition_PrependLogFile_Write_Fail and TestPartition_Compact_Write_Fail on Windows === FAIL: tsdb/index/tsi1 TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_PrependLogFile_Write_Failwrite_MANIFEST656030081\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) === FAIL: tsdb/index/tsi1 TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_Compact_Write_Failwrite_MANIFEST3398667527\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) We must close the open file descriptor otherwise the temporary file cannot be cleaned up on Windows. Fixes: 619eb1cae6 ("fix: restore in-memory Manifest on write error") Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestReplicationStartMissingQueue on Windows === FAIL: TestReplicationStartMissingQueue (1.60s) logger.go:130: 2023-03-17T10:42:07.269Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} logger.go:130: 2023-03-17T10:42:07.305Z INFO Opened replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestReplicationStartMissingQueue76668607\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: update TestWAL_DiskSize Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestWAL_DiskSize on Windows === FAIL: tsdb/engine/tsm1 TestWAL_DiskSize (2.65s) testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestWAL_DiskSize2736073801\001\_00006.wal: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> --------- Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-03-21 20:22:11 +00:00
svc := newTestService(t)
ctx := context.Background()
// attempting to delete a non-existant notebook should return an error
err := svc.DeleteNotebook(ctx, idGen.ID())
fmt.Println(err)
require.ErrorIs(t, influxdb.ErrNotebookNotFound, err)
testCreate := &influxdb.NotebookReqBody{
OrgID: idGen.ID(),
Name: "some name",
Spec: map[string]interface{}{"hello": "goodbye"},
}
// create the notebook that we are going to try to delete
gotCreate, err := svc.CreateNotebook(ctx, testCreate)
require.NoError(t, err)
gotCreateBody := &influxdb.NotebookReqBody{
OrgID: gotCreate.OrgID,
Name: gotCreate.Name,
Spec: gotCreate.Spec,
}
require.Equal(t, testCreate, gotCreateBody)
// should be able to successfully delete the notebook now
err = svc.DeleteNotebook(ctx, gotCreate.ID)
require.NoError(t, err)
// ensure the notebook no longer exists
_, err = svc.GetNotebook(ctx, gotCreate.ID)
require.ErrorIs(t, influxdb.ErrNotebookNotFound, err)
}
func TestList(t *testing.T) {
t.Parallel()
test: use `T.TempDir` to create temporary test directory (#23258) * test: use `T.TempDir` to create temporary test directory This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `os.MkdirTemp` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestSendWrite on Windows === FAIL: replications/internal TestSendWrite (0.29s) logger.go:130: 2022-06-23T13:00:54.290Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestSendWrite1627281409\\001\\replicationq\\0000000000000001"} logger.go:130: 2022-06-23T13:00:54.457Z ERROR Error in replication stream {"replication_id": "0000000000000001", "error": "remote timeout", "retries": 1} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestSendWrite1627281409\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestStore_BadShard on Windows === FAIL: tsdb TestStore_BadShard (0.09s) logger.go:130: 2022-06-23T12:18:21.827Z INFO Using data dir {"service": "store", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestStore_BadShard1363295568\\001"} logger.go:130: 2022-06-23T12:18:21.827Z INFO Compaction settings {"service": "store", "max_concurrent_compactions": 2, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (start) {"service": "store", "op_name": "tsdb_open", "op_event": "start"} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (end) {"service": "store", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "77.3µs"} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestStore_BadShard1363295568\002\data\db0\rp0\1\index\0\L0-00000001.tsl: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestPartition_PrependLogFile_Write_Fail and TestPartition_Compact_Write_Fail on Windows === FAIL: tsdb/index/tsi1 TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_PrependLogFile_Write_Failwrite_MANIFEST656030081\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) === FAIL: tsdb/index/tsi1 TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_Compact_Write_Failwrite_MANIFEST3398667527\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) We must close the open file descriptor otherwise the temporary file cannot be cleaned up on Windows. Fixes: 619eb1cae6 ("fix: restore in-memory Manifest on write error") Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestReplicationStartMissingQueue on Windows === FAIL: TestReplicationStartMissingQueue (1.60s) logger.go:130: 2023-03-17T10:42:07.269Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} logger.go:130: 2023-03-17T10:42:07.305Z INFO Opened replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestReplicationStartMissingQueue76668607\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: update TestWAL_DiskSize Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestWAL_DiskSize on Windows === FAIL: tsdb/engine/tsm1 TestWAL_DiskSize (2.65s) testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestWAL_DiskSize2736073801\001\_00006.wal: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> --------- Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-03-21 20:22:11 +00:00
svc := newTestService(t)
ctx := context.Background()
orgID := idGen.ID()
// selecting with no matches for org_id should return an empty list and no error
got, err := svc.ListNotebooks(ctx, influxdb.NotebookListFilter{OrgID: orgID})
require.NoError(t, err)
require.Equal(t, []*influxdb.Notebook{}, got)
// create some notebooks to test the list operation with
creates := []*influxdb.NotebookReqBody{
{
OrgID: orgID,
Name: "some name",
Spec: map[string]interface{}{"hello": "goodbye"},
},
{
OrgID: orgID,
Name: "another name",
Spec: map[string]interface{}{"aloha": "aloha"},
},
{
OrgID: orgID,
Name: "some name",
Spec: map[string]interface{}{"hola": "adios"},
},
}
for _, c := range creates {
_, err := svc.CreateNotebook(ctx, c)
require.NoError(t, err)
}
// there should now be notebooks returned from ListNotebooks
got, err = svc.ListNotebooks(ctx, influxdb.NotebookListFilter{OrgID: orgID})
require.NoError(t, err)
require.Equal(t, len(creates), len(got))
// make sure the elements from the returned list were from the list of notebooks to create
for _, n := range got {
require.Contains(t, creates, &influxdb.NotebookReqBody{
OrgID: n.OrgID,
Name: n.Name,
Spec: n.Spec,
})
}
}
test: use `T.TempDir` to create temporary test directory (#23258) * test: use `T.TempDir` to create temporary test directory This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `os.MkdirTemp` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestSendWrite on Windows === FAIL: replications/internal TestSendWrite (0.29s) logger.go:130: 2022-06-23T13:00:54.290Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestSendWrite1627281409\\001\\replicationq\\0000000000000001"} logger.go:130: 2022-06-23T13:00:54.457Z ERROR Error in replication stream {"replication_id": "0000000000000001", "error": "remote timeout", "retries": 1} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestSendWrite1627281409\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestStore_BadShard on Windows === FAIL: tsdb TestStore_BadShard (0.09s) logger.go:130: 2022-06-23T12:18:21.827Z INFO Using data dir {"service": "store", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestStore_BadShard1363295568\\001"} logger.go:130: 2022-06-23T12:18:21.827Z INFO Compaction settings {"service": "store", "max_concurrent_compactions": 2, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (start) {"service": "store", "op_name": "tsdb_open", "op_event": "start"} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (end) {"service": "store", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "77.3µs"} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestStore_BadShard1363295568\002\data\db0\rp0\1\index\0\L0-00000001.tsl: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestPartition_PrependLogFile_Write_Fail and TestPartition_Compact_Write_Fail on Windows === FAIL: tsdb/index/tsi1 TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_PrependLogFile_Write_Failwrite_MANIFEST656030081\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) === FAIL: tsdb/index/tsi1 TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_Compact_Write_Failwrite_MANIFEST3398667527\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) We must close the open file descriptor otherwise the temporary file cannot be cleaned up on Windows. Fixes: 619eb1cae6 ("fix: restore in-memory Manifest on write error") Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestReplicationStartMissingQueue on Windows === FAIL: TestReplicationStartMissingQueue (1.60s) logger.go:130: 2023-03-17T10:42:07.269Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} logger.go:130: 2023-03-17T10:42:07.305Z INFO Opened replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestReplicationStartMissingQueue76668607\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: update TestWAL_DiskSize Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestWAL_DiskSize on Windows === FAIL: tsdb/engine/tsm1 TestWAL_DiskSize (2.65s) testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestWAL_DiskSize2736073801\001\_00006.wal: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> --------- Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-03-21 20:22:11 +00:00
func newTestService(t *testing.T) *Service {
store := sqlite.NewTestStore(t)
ctx := context.Background()
sqliteMigrator := sqlite.NewMigrator(store, zap.NewNop())
err := sqliteMigrator.Up(ctx, migrations.AllUp)
require.NoError(t, err)
svc := NewService(store)
test: use `T.TempDir` to create temporary test directory (#23258) * test: use `T.TempDir` to create temporary test directory This commit replaces `os.MkdirTemp` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `os.MkdirTemp` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestSendWrite on Windows === FAIL: replications/internal TestSendWrite (0.29s) logger.go:130: 2022-06-23T13:00:54.290Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestSendWrite1627281409\\001\\replicationq\\0000000000000001"} logger.go:130: 2022-06-23T13:00:54.457Z ERROR Error in replication stream {"replication_id": "0000000000000001", "error": "remote timeout", "retries": 1} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestSendWrite1627281409\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestStore_BadShard on Windows === FAIL: tsdb TestStore_BadShard (0.09s) logger.go:130: 2022-06-23T12:18:21.827Z INFO Using data dir {"service": "store", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestStore_BadShard1363295568\\001"} logger.go:130: 2022-06-23T12:18:21.827Z INFO Compaction settings {"service": "store", "max_concurrent_compactions": 2, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (start) {"service": "store", "op_name": "tsdb_open", "op_event": "start"} logger.go:130: 2022-06-23T12:18:21.828Z INFO Open store (end) {"service": "store", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "77.3µs"} testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestStore_BadShard1363295568\002\data\db0\rp0\1\index\0\L0-00000001.tsl: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestPartition_PrependLogFile_Write_Fail and TestPartition_Compact_Write_Fail on Windows === FAIL: tsdb/index/tsi1 TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_PrependLogFile_Write_Failwrite_MANIFEST656030081\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_PrependLogFile_Write_Fail/write_MANIFEST (0.06s) === FAIL: tsdb/index/tsi1 TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestPartition_Compact_Write_Failwrite_MANIFEST3398667527\002\0\L0-00000003.tsl: The process cannot access the file because it is being used by another process. --- FAIL: TestPartition_Compact_Write_Fail/write_MANIFEST (0.08s) We must close the open file descriptor otherwise the temporary file cannot be cleaned up on Windows. Fixes: 619eb1cae6 ("fix: restore in-memory Manifest on write error") Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestReplicationStartMissingQueue on Windows === FAIL: TestReplicationStartMissingQueue (1.60s) logger.go:130: 2023-03-17T10:42:07.269Z DEBUG Created new durable queue for replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} logger.go:130: 2023-03-17T10:42:07.305Z INFO Opened replication stream {"id": "0000000000000001", "path": "C:\\Users\\circleci\\AppData\\Local\\Temp\\TestReplicationStartMissingQueue76668607\\001\\replicationq\\0000000000000001"} testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestReplicationStartMissingQueue76668607\001\replicationq\0000000000000001\1: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: update TestWAL_DiskSize Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * test: fix failing TestWAL_DiskSize on Windows === FAIL: tsdb/engine/tsm1 TestWAL_DiskSize (2.65s) testing.go:1206: TempDir RemoveAll cleanup: remove C:\Users\circleci\AppData\Local\Temp\TestWAL_DiskSize2736073801\001\_00006.wal: The process cannot access the file because it is being used by another process. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> --------- Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-03-21 20:22:11 +00:00
return svc
}