Add concurrent table update test

This commit is contained in:
Mura Li 2017-04-08 20:36:51 +08:00
parent a5cb21c443
commit 4b86b764f4
1 changed files with 33 additions and 0 deletions

View File

@ -5,6 +5,8 @@
package xorm package xorm
import ( import (
"fmt"
"sync"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -72,3 +74,34 @@ func TestUpdateLimit(t *testing.T) {
assert.EqualValues(t, 35, uts[0].Age) assert.EqualValues(t, 35, uts[0].Age)
assert.EqualValues(t, 30, uts[1].Age) assert.EqualValues(t, 30, uts[1].Age)
} }
func TestUpdateMapConcurrently(t *testing.T) {
assert.NoError(t, prepareEngine())
type UpdateTable struct {
Id int64
Name string
Age int
}
assert.NoError(t, testEngine.Sync2(new(UpdateTable)))
var tb = UpdateTable{
Name: "test",
Age: 35,
}
wg := sync.WaitGroup{}
for i := 0; i < 10000; i++ {
wg.Add(1)
go func() {
// We don't check return errors for the sake of simplicity as the main point is data races.
testEngine.Insert(&tb)
testEngine.Table("update_table").Where("id = ?", tb.Id).Update(map[string]interface{}{
"name": "test2",
"age": fmt.Sprintf("%d", i),
})
wg.Done()
}()
}
wg.Wait()
}