mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-04-19 03:01:06 -04:00
**What type of PR is this?** Other **What does this PR do? Why is it needed?** Follow up to https://github.com/OffchainLabs/prysm/pull/16215 this pr improves logging, fixes stuttering in package naming, adds additional unit tests, and deduplicates fallback node code. **Which issues(s) does this PR fix?** fixes a potential race if reconnecting to the same host very quickly which has a stale connection still. **Other notes for review** **Acknowledgements** - [x] I have read [CONTRIBUTING.md](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md). - [x] I have included a uniquely named [changelog fragment file](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md#maintaining-changelogmd). - [x] I have added a description with sufficient context for reviewers to understand this PR. - [x] I have tested that my changes work as expected and I added a testing plan to the PR description (if applicable).
28 lines
762 B
Go
28 lines
762 B
Go
package grpc
|
|
|
|
import "google.golang.org/grpc"
|
|
|
|
// MockGrpcProvider implements GrpcConnectionProvider for testing.
|
|
type MockGrpcProvider struct {
|
|
MockConn *grpc.ClientConn
|
|
MockHosts []string
|
|
CurrentIndex int
|
|
ConnCounter uint64
|
|
}
|
|
|
|
func (m *MockGrpcProvider) CurrentConn() *grpc.ClientConn { return m.MockConn }
|
|
func (m *MockGrpcProvider) CurrentHost() string {
|
|
if len(m.MockHosts) > 0 {
|
|
return m.MockHosts[m.CurrentIndex]
|
|
}
|
|
return ""
|
|
}
|
|
func (m *MockGrpcProvider) Hosts() []string { return m.MockHosts }
|
|
func (m *MockGrpcProvider) SwitchHost(idx int) error {
|
|
m.CurrentIndex = idx
|
|
m.ConnCounter++
|
|
return nil
|
|
}
|
|
func (m *MockGrpcProvider) ConnectionCounter() uint64 { return m.ConnCounter }
|
|
func (m *MockGrpcProvider) Close() {}
|