From d08d14e80193c19b7f45c19e8c11cdc1e6c344b6 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Thu, 10 Oct 2024 12:05:36 -0700 Subject: [PATCH] checkpoint Signed-off-by: Jeff Ortel --- database/db_test.go | 42 ++++++++++++++++++++++++++++++++++++++++-- database/pkg.go | 2 +- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/database/db_test.go b/database/db_test.go index f490186e..3a4590f0 100644 --- a/database/db_test.go +++ b/database/db_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm" "k8s.io/utils/env" @@ -57,12 +58,35 @@ func TestConcurrent(t *testing.T) { if err != nil { panic(err) } + + type A struct { + model.Model + } + + type B struct { + N int + model.Model + A A + AID uint + } + err = db.Migrator().AutoMigrate(&A{}, &B{}) + if err != nil { + panic(err) + } + + a := A{} + err = db.Create(&a).Error + if err != nil { + panic(err) + } + dq := make(chan int, N) for w := 0; w < N; w++ { go func(id int) { fmt.Printf("Started %d\n", id) - for n := 0; n < N*10; n++ { - m := &model.Setting{Key: fmt.Sprintf("key-%d-%d", id, n), Value: n} + for n := 0; n < N*100; n++ { + m := &B{N: n, A: a} + m.CreateUser = "Test" fmt.Printf("(%.4d) CREATE: %.4d\n", id, n) uErr := db.Create(m).Error if uErr != nil { @@ -79,6 +103,20 @@ func TestConcurrent(t *testing.T) { panic(uErr) } } + for i := 0; i < 10; i++ { + fmt.Printf("(%.4d) LIST: %.4d/%.4d\n", id, n, i) + page := api.Page{} + cursor := api.Cursor{} + mx := B{} + dbx := db.Model(mx) + dbx = dbx.Joins("A") + dbx = dbx.Limit(10) + cursor.With(dbx, page) + for cursor.Next(&mx) { + time.Sleep(time.Millisecond + 10) + fmt.Printf("(%.4d) NEXT: %.4d/%.4d ID=%d\n", id, n, i, mx.ID) + } + } for i := 0; i < 4; i++ { uErr = db.Transaction(func(tx *gorm.DB) (err error) { time.Sleep(time.Millisecond * 10) diff --git a/database/pkg.go b/database/pkg.go index 6e9c5eb2..83cfc4f3 100644 --- a/database/pkg.go +++ b/database/pkg.go @@ -18,7 +18,7 @@ var log = logr.WithName("db") var Settings = &settings.Settings const ( - ConnectionString = "file:%s?_journal=WAL&_timeout=100" + ConnectionString = "file:%s?_journal=WAL" FKsOn = "&_foreign_keys=yes" FKsOff = "&_foreign_keys=no" )