From 76bc83ea2b93368c92b227cd0033846a50775ed3 Mon Sep 17 00:00:00 2001 From: ktsivkov Date: Mon, 20 Mar 2023 16:16:34 +0100 Subject: [PATCH] Fixed tests for Easer to use gorm.open in order to inject the required configurations --- gorm.go | 12 ++++++------ tests/easer_test.go | 11 +++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/gorm.go b/gorm.go index baa3a594..c3db1297 100644 --- a/gorm.go +++ b/gorm.go @@ -57,11 +57,11 @@ type Config struct { // Plugins registered plugins Plugins map[string]Plugin // Ease database load by grouping identical queries - Ease bool - EaseQueue *sync.Map + Ease bool callbacks *callbacks cacheStore *sync.Map + easeQueue *sync.Map } // Apply update config to new config @@ -170,8 +170,8 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) { config.cacheStore = &sync.Map{} } - if config.Ease && config.EaseQueue == nil { - config.EaseQueue = &sync.Map{} + if config.Ease && config.easeQueue == nil { + config.easeQueue = &sync.Map{} } db = &DB{Config: config, clone: 1} @@ -501,13 +501,13 @@ func (db *DB) Ease(cb func(*DB)) *DB { } eq.wg.Add(1) - var runner, ok = db.EaseQueue.LoadOrStore(hash, eq) + var runner, ok = db.easeQueue.LoadOrStore(hash, eq) et := runner.(*easedTask) if !ok { cb(db) et.wg.Done() - db.EaseQueue.Delete(hash) + db.easeQueue.Delete(hash) return db } diff --git a/tests/easer_test.go b/tests/easer_test.go index a1a7c607..74b26af4 100644 --- a/tests/easer_test.go +++ b/tests/easer_test.go @@ -2,6 +2,7 @@ package tests_test import ( "gorm.io/gorm" + "gorm.io/gorm/utils/tests" "sync" "testing" "time" @@ -9,8 +10,9 @@ import ( func TestEaser(t *testing.T) { t.Run("once", func(t *testing.T) { - db1 := DB.Unscoped() - db1.Config.EaseQueue = &sync.Map{} + db1, _ := gorm.Open(tests.DummyDialector{}, &gorm.Config{ + Ease: true, + }) wg := &sync.WaitGroup{} wg.Add(2) @@ -40,8 +42,9 @@ func TestEaser(t *testing.T) { } }) t.Run("twice", func(t *testing.T) { - db1 := DB.Unscoped() - db1.Config.EaseQueue = &sync.Map{} + db1, _ := gorm.Open(tests.DummyDialector{}, &gorm.Config{ + Ease: true, + }) wg := &sync.WaitGroup{} wg.Add(2)