2019-05-22 23:16:55 +02:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTableOpenClose(t *testing.T) {
|
|
|
|
const path = "TestTableOpenClose"
|
2020-10-20 13:29:26 +02:00
|
|
|
const retentionMsecs = 123 * msecsPerMonth
|
2019-05-22 23:16:55 +02:00
|
|
|
|
|
|
|
if err := os.RemoveAll(path); err != nil {
|
|
|
|
t.Fatalf("cannot remove %q: %s", path, err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
_ = os.RemoveAll(path)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Create a new table
|
2022-06-01 13:21:12 +02:00
|
|
|
var isReadOnly uint32
|
|
|
|
tb, err := openTable(path, nilGetDeletedMetricIDs, retentionMsecs, &isReadOnly)
|
2019-05-22 23:16:55 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("cannot create new table: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close it
|
|
|
|
tb.MustClose()
|
|
|
|
|
|
|
|
// Re-open created table multiple times.
|
|
|
|
for i := 0; i < 10; i++ {
|
2022-06-01 13:21:12 +02:00
|
|
|
tb, err := openTable(path, nilGetDeletedMetricIDs, retentionMsecs, &isReadOnly)
|
2019-05-22 23:16:55 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("cannot open created table: %s", err)
|
|
|
|
}
|
|
|
|
tb.MustClose()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTableOpenMultipleTimes(t *testing.T) {
|
|
|
|
const path = "TestTableOpenMultipleTimes"
|
2020-10-20 13:29:26 +02:00
|
|
|
const retentionMsecs = 123 * msecsPerMonth
|
2019-05-22 23:16:55 +02:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
_ = os.RemoveAll(path)
|
|
|
|
}()
|
|
|
|
|
2022-06-01 13:21:12 +02:00
|
|
|
var isReadOnly uint32
|
|
|
|
tb1, err := openTable(path, nilGetDeletedMetricIDs, retentionMsecs, &isReadOnly)
|
2019-05-22 23:16:55 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("cannot open table the first time: %s", err)
|
|
|
|
}
|
|
|
|
defer tb1.MustClose()
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2022-06-01 13:21:12 +02:00
|
|
|
tb2, err := openTable(path, nilGetDeletedMetricIDs, retentionMsecs, &isReadOnly)
|
2019-05-22 23:16:55 +02:00
|
|
|
if err == nil {
|
|
|
|
tb2.MustClose()
|
|
|
|
t.Fatalf("expecting non-nil error when opening already opened table")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|