Created
January 31, 2020 13:56
-
-
Save abuiles/1af35dea9b1972e9423d1c8ed775aeef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/exp/ingest/io/postgres_temp_set.go b/exp/ingest/io/postgres_temp_set.go | |
index 4ca7432b..3d097a7c 100644 | |
--- a/exp/ingest/io/postgres_temp_set.go | |
+++ b/exp/ingest/io/postgres_temp_set.go | |
@@ -31,7 +31,7 @@ const ( | |
// If `Session` is passed, it will be cloned. | |
type PostgresTempSet struct { | |
DSN string | |
- Session *db.Session | |
+ Session db.SessionInterface | |
afterFirstDump bool | |
// cache can contain both true and false values. false values can be set | |
diff --git a/services/horizon/internal/db2/history/main.go b/services/horizon/internal/db2/history/main.go | |
index 9847f47f..e763d208 100644 | |
--- a/services/horizon/internal/db2/history/main.go | |
+++ b/services/horizon/internal/db2/history/main.go | |
@@ -454,6 +454,8 @@ type Q struct { | |
*db.Session | |
} | |
+var _ db.SessionInterface = (*Q)(nil) | |
+ | |
// QSigners defines signer related queries. | |
type QSigners interface { | |
GetLastLedgerExpIngestNonBlocking() (uint32, error) | |
diff --git a/services/horizon/internal/expingest/main.go b/services/horizon/internal/expingest/main.go | |
index 1be00df1..835aab8c 100644 | |
--- a/services/horizon/internal/expingest/main.go | |
+++ b/services/horizon/internal/expingest/main.go | |
@@ -93,7 +93,7 @@ type dbQ interface { | |
Begin() error | |
Commit() error | |
- Clone() *db.Session | |
+ Clone() db.SessionInterface | |
Rollback() error | |
GetTx() *sqlx.Tx | |
GetExpIngestVersion() (int, error) | |
@@ -184,7 +184,8 @@ func NewSystem(config Config) (*System, error) { | |
return nil, errors.Wrap(err, "error creating ledger backend") | |
} | |
- historyQ := &history.Q{config.HistorySession.Clone()} | |
+ clone, _ := config.HistorySession.Clone() | |
+ historyQ := &history.Q{&clone} | |
historyAdapter := adapters.MakeHistoryArchiveAdapter(archive) | |
diff --git a/services/horizon/internal/expingest/main_test.go b/services/horizon/internal/expingest/main_test.go | |
index 4e121723..f54d2c42 100644 | |
--- a/services/horizon/internal/expingest/main_test.go | |
+++ b/services/horizon/internal/expingest/main_test.go | |
@@ -4,7 +4,6 @@ import ( | |
"context" | |
"testing" | |
- "github.com/jmoiron/sqlx" | |
"github.com/stellar/go/services/horizon/internal/db2/history" | |
"github.com/stellar/go/support/db" | |
"github.com/stellar/go/support/errors" | |
@@ -45,6 +44,7 @@ func TestStateMachineRunReturnsErrorWhenNextStateIsShutdownWithError(t *testing. | |
type mockDBQ struct { | |
mock.Mock | |
+ db.MockSession | |
history.MockQAccounts | |
history.MockQAssetStats | |
@@ -58,34 +58,13 @@ type mockDBQ struct { | |
history.MockQTrustLines | |
} | |
-func (m *mockDBQ) Begin() error { | |
- args := m.Called() | |
- return args.Error(0) | |
-} | |
- | |
-func (m *mockDBQ) Clone() *db.Session { | |
- args := m.Called() | |
- return args.Get(0).(*db.Session) | |
-} | |
+var _ db.SessionInterface = (*mockDBQ)(nil) | |
func (m *mockDBQ) Commit() error { | |
args := m.Called() | |
return args.Error(0) | |
} | |
-func (m *mockDBQ) Rollback() error { | |
- args := m.Called() | |
- return args.Error(0) | |
-} | |
- | |
-func (m *mockDBQ) GetTx() *sqlx.Tx { | |
- args := m.Called() | |
- if args.Get(0) == nil { | |
- return nil | |
- } | |
- return args.Get(0).(*sqlx.Tx) | |
-} | |
- | |
func (m *mockDBQ) GetLastLedgerExpIngest() (uint32, error) { | |
args := m.Called() | |
return args.Get(0).(uint32), args.Error(1) | |
diff --git a/support/db/main.go b/support/db/main.go | |
index b625b174..05bb8547 100644 | |
--- a/support/db/main.go | |
+++ b/support/db/main.go | |
@@ -134,13 +134,14 @@ type SessionInterface interface { | |
Begin() error | |
Rollback() error | |
TruncateTables(tables []string) error | |
- Clone() *Session | |
+ Clone() SessionInterface | |
Close() error | |
Get(dest interface{}, query squirrel.Sqlizer) error | |
GetRaw(dest interface{}, query string, args ...interface{}) error | |
Select(dest interface{}, query squirrel.Sqlizer) error | |
SelectRaw(dest interface{}, query string, args ...interface{}) error | |
GetTable(name string) *Table | |
+ GetTx() *sqlx.Tx | |
Exec(query squirrel.Sqlizer) (sql.Result, error) | |
ExecRaw(query string, args ...interface{}) (sql.Result, error) | |
NoRows(err error) bool | |
diff --git a/support/db/mock_session.go b/support/db/mock_session.go | |
index fe96d622..029c3026 100644 | |
--- a/support/db/mock_session.go | |
+++ b/support/db/mock_session.go | |
@@ -5,6 +5,7 @@ import ( | |
"github.com/Masterminds/squirrel" | |
sq "github.com/Masterminds/squirrel" | |
+ "github.com/jmoiron/sqlx" | |
"github.com/stretchr/testify/mock" | |
) | |
@@ -29,9 +30,9 @@ func (m *MockSession) TruncateTables(tables []string) error { | |
return args.Error(0) | |
} | |
-func (m *MockSession) Clone() *Session { | |
+func (m *MockSession) Clone() SessionInterface { | |
args := m.Called() | |
- return args.Get(0).(*Session) | |
+ return args.Get(0).(SessionInterface) | |
} | |
func (m *MockSession) Close() error { | |
@@ -49,6 +50,14 @@ func (m *MockSession) GetRaw(dest interface{}, query string, args ...interface{} | |
return argss.Error(0) | |
} | |
+func (m *MockSession) GetTx() *sqlx.Tx { | |
+ args := m.Called() | |
+ if args.Get(0) == nil { | |
+ return nil | |
+ } | |
+ return args.Get(0).(*sqlx.Tx) | |
+} | |
+ | |
func (m *MockSession) Select(dest interface{}, query squirrel.Sqlizer) error { | |
argss := m.Called(dest, query) | |
return argss.Error(0) | |
diff --git a/support/db/session.go b/support/db/session.go | |
index 799af9fc..b4df3b54 100644 | |
--- a/support/db/session.go | |
+++ b/support/db/session.go | |
@@ -63,7 +63,7 @@ func (s *Session) GetTx() *sqlx.Tx { | |
// Clone clones the receiver, returning a new instance backed by the same | |
// context and db. The result will not be bound to any transaction that the | |
// source is currently within. | |
-func (s *Session) Clone() *Session { | |
+func (s *Session) Clone() SessionInterface { | |
return &Session{ | |
DB: s.DB, | |
Ctx: s.Ctx, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment