Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: build time performance #315

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,7 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457 h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk=
Expand Down
2 changes: 1 addition & 1 deletion internal/tests/basic/gen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package basic
package main

//go:generate go run ../../../cmd/som/main.go -- gen ./model ./gen/som
33 changes: 33 additions & 0 deletions internal/tests/basic/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"context"
"github.com/brianvoe/gofakeit/v7"
"github.com/docker/docker/api/types/container"
"github.com/go-surreal/som/tests/basic/gen/som"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"log/slog"
"os"
)

const (
surrealDBVersion = "2.1.3"
containerStartedMsg = "Started web server on "
)

func main() {
ctx := context.Background()

client, cleanup, err := prepareDatabase(ctx, "main")
if err != nil {
panic(err)
}

defer cleanup()

_, err = client.AllFieldTypesRepo().Query().All(ctx)
if err != nil {
panic(err)
}
}
24 changes: 12 additions & 12 deletions internal/tests/basic/som_base_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package basic
package main

import (
"context"
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestQuery(t *testing.T) {
func TestWithDatabase(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

str := "Some User"
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestWithDatabase(t *testing.T) {
func TestNumerics(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

str := "user"
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestNumerics(t *testing.T) {
func TestTimestamps(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

user := &model.AllFieldTypes{}
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestTimestamps(t *testing.T) {
func TestURLTypes(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

someURL, err := url.Parse("https://surrealdb.com")
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestURLTypes(t *testing.T) {
func TestDuration(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

ptr := time.Hour
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestDuration(t *testing.T) {
func TestUUID(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

ptr := uuid.New()
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestUUID(t *testing.T) {
func FuzzWithDatabase(f *testing.F) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, f)
client, cleanup := prepareTestDatabase(ctx, f)
defer cleanup()

f.Add("Some User")
Expand Down Expand Up @@ -430,7 +430,7 @@ func FuzzWithDatabase(f *testing.F) {
func FuzzCustomModelIDs(f *testing.F) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, f)
client, cleanup := prepareTestDatabase(ctx, f)
defer cleanup()

f.Add("v9uitj942tv2403tnv")
Expand Down Expand Up @@ -492,7 +492,7 @@ func FuzzCustomModelIDs(f *testing.F) {
func BenchmarkWithDatabase(b *testing.B) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, b)
client, cleanup := prepareTestDatabase(ctx, b)
defer cleanup()

b.ResetTimer()
Expand Down Expand Up @@ -528,7 +528,7 @@ func BenchmarkWithDatabase(b *testing.B) {
func TestAsync(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

err := client.AllFieldTypesRepo().Create(ctx, &model.AllFieldTypes{})
Expand Down Expand Up @@ -559,7 +559,7 @@ func TestAsync(t *testing.T) {
func TestRefresh(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

allFieldTypes := &model.AllFieldTypes{
Expand Down
4 changes: 2 additions & 2 deletions internal/tests/basic/som_count_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package basic
package main

import (
"context"
Expand All @@ -16,7 +16,7 @@ const (
func TestQueryCount(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

if err := client.ApplySchema(ctx); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/tests/basic/som_filter_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package basic
package main

import (
"context"
Expand All @@ -16,7 +16,7 @@ func TestFilterCompareFields(t *testing.T) {

ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

str := "Some Value"
Expand Down
2 changes: 1 addition & 1 deletion internal/tests/basic/som_integrity_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package basic
package main

import (
"io/fs"
Expand Down
10 changes: 5 additions & 5 deletions internal/tests/basic/som_live_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package basic
package main

import (
"context"
Expand All @@ -15,7 +15,7 @@ import (
func TestCreateWithFieldsLikeDBResponse(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

newModel := &model.FieldsLikeDBResponse{
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestCreateWithFieldsLikeDBResponse(t *testing.T) {
func TestLiveQueries(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

ctx, cancel := context.WithCancel(ctx)
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestLiveQueries(t *testing.T) {
func TestLiveQueriesFilter(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

liveChan, err := client.FieldsLikeDBResponseRepo().Query().
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestLiveQueriesFilter(t *testing.T) {
func TestLiveQueryCount(t *testing.T) {
ctx := context.Background()

client, cleanup := prepareDatabase(ctx, t)
client, cleanup := prepareTestDatabase(ctx, t)
defer cleanup()

ctx, cancel := context.WithCancel(ctx)
Expand Down
15 changes: 9 additions & 6 deletions internal/tests/basic/som_prepare_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package basic
package main

import (
"context"
Expand All @@ -14,11 +14,6 @@ import (
"testing"
)

const (
surrealDBVersion = "2.1.3"
containerStartedMsg = "Started web server on "
)

// errAlreadyInProgress is a regular expression that matches the
// error for a container removal that is already in progress.
var errAlreadyInProgress = regexp.MustCompile(`removal of container .* is already in progress`)
Expand Down Expand Up @@ -97,6 +92,14 @@ func prepareDatabase(ctx context.Context, tb testing.TB) (som.Client, func()) {
tb.Fatal(err)
}

//err = client.Execute(ctx,
// "DEFINE INDEX OVERWRITE test ON "+client.TableAllFieldTypes()+" FIELDS string, string_ptr CONCURRENTLY;", // or: IF NOT EXISTS
// map[string]any{}, // INFO FOR TABLE all_field_types; shows the status of the index
//) // REBUILD
//if err != nil {
// tb.Fatal(err)
//}

cleanup := func() {
client.Close()

Expand Down
Loading