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 Aug 21, 2024
1 parent 6e6e2e6 commit 83461a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
32 changes: 23 additions & 9 deletions database/db_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package database

import (
"encoding/json"
"fmt"
"os"
"testing"
"time"

"github.com/konveyor/tackle2-hub/model"
"gorm.io/gorm"
"k8s.io/utils/env"
)

Expand All @@ -26,25 +27,38 @@ func TestConcurrent(t *testing.T) {
for w := 0; w < N; w++ {
go func(id int) {
fmt.Printf("Started %d\n", id)
for n := 0; n < N; n++ {
v, _ := json.Marshal(fmt.Sprintf("Test-%d", n))
m := &model.Setting{Key: fmt.Sprintf("key-%d-%d", id, n), Value: v}
for n := 0; n < N*10; n++ {
m := &model.Setting{Key: fmt.Sprintf("key-%d-%d", id, n), Value: n}
fmt.Printf("(%.4d) CREATE: %.4d\n", id, n)
uErr := db.Create(m).Error
if uErr != nil {
panic(uErr)
}
for i := 0; i < 3; i++ {
tx := db.Begin()
uErr = tx.First(m).Error
uErr = db.Save(m).Error
if uErr != nil {
panic(uErr)
}
for i := 0; i < 10; i++ {
fmt.Printf("(%.4d) READ: %.4d/%.4d\n", id, n, i)
uErr = db.First(m).Error
if uErr != nil {
panic(uErr)
}
uErr = tx.Save(m).Error
}
for i := 0; i < 4; i++ {
uErr = db.Transaction(func(tx *gorm.DB) (err error) {
time.Sleep(time.Millisecond * 10)
for i := 0; i < 3; i++ {
err = tx.Save(m).Error
if err != nil {
break
}
}
return
})
if uErr != nil {
panic(uErr)
}
tx.Commit()
}
}
dq <- id
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"
ConnectionString = "file:%s?_journal=WAL&_timeout=100"
FKsOn = "&_foreign_keys=yes"
FKsOff = "&_foreign_keys=no"
)
Expand Down

0 comments on commit 83461a0

Please sign in to comment.