Add test that provokes the race condition

This commit is contained in:
Lasse Hyldahl Jensen 2023-11-08 21:00:26 +01:00
parent 40f4afe8c2
commit 34440dafd8

View File

@ -1685,3 +1685,29 @@ func TestTableType(t *testing.T) {
t.Fatalf("expected comment %s got %s", tblComment, comment)
}
}
func TestMigrateRaceCondition(t *testing.T) {
type TestTable struct {
gorm.Model
}
for a := 0; a < 2; a++ {
t.Run("drop and migrate", func(t *testing.T) {
t.Run("drop", func(t *testing.T) {
if err := DB.Migrator().DropTable(&TestTable{}); err != nil {
t.Fatalf("failed to drop table: %v", err)
}
})
for i := 0; i < 2; i++ {
t.Run("migrate", func(t *testing.T) {
t.Parallel()
if err := DB.AutoMigrate(&TestTable{}); err != nil {
t.Fatalf("failed to migrate: %v", err)
}
})
}
})
}
}