Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Oct 10, 2024
1 parent a6cc2f0 commit d08d14e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
42 changes: 40 additions & 2 deletions database/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion database/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit d08d14e

Please sign in to comment.