You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_fixtures.go 957B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. "time"
  8. "gopkg.in/testfixtures.v2"
  9. )
  10. var fixtures *testfixtures.Context
  11. // InitFixtures initialize test fixtures for a test database
  12. func InitFixtures(helper testfixtures.Helper, dir string) (err error) {
  13. testfixtures.SkipDatabaseNameCheck(true)
  14. fixtures, err = testfixtures.NewFolder(x.DB().DB, helper, dir)
  15. return err
  16. }
  17. // LoadFixtures load fixtures for a test database
  18. func LoadFixtures() error {
  19. var err error
  20. // Database transaction conflicts could occur and result in ROLLBACK
  21. // As a simple workaround, we just retry 20 times.
  22. for i := 0; i < 20; i++ {
  23. err = fixtures.Load()
  24. if err == nil {
  25. break
  26. }
  27. time.Sleep(200 * time.Millisecond)
  28. }
  29. if err != nil {
  30. fmt.Printf("LoadFixtures failed after retries: %v\n", err)
  31. }
  32. return err
  33. }