本站源代码
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.

40 lines
957B

  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. }
上海开阖软件有限公司 沪ICP备12045867号-1