Skip to content

Commit

Permalink
The Ping method of api.Connection is unused - remove it.
Browse files Browse the repository at this point in the history
  • Loading branch information
arnodel committed Apr 5, 2022
1 parent 535b259 commit e157566
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
8 changes: 4 additions & 4 deletions api/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func Open(info *Info, opts DialOpts) (Connection, error) {

go (&monitor{
clock: opts.Clock,
ping: st.Ping,
ping: st.ping,
pingPeriod: PingPeriod,
pingTimeout: pingTimeout,
closed: st.closed,
Expand Down Expand Up @@ -551,8 +551,8 @@ func (st *state) apiEndpoint(path, query string) (*url.URL, error) {
}, nil
}

// Ping implements api.Connection.
func (s *state) Ping() error {
// ping implements calls the Pinger.ping facade.
func (s *state) ping() error {
return s.APICall("Pinger", s.pingerFacadeVersion, "", "Ping", nil, nil)
}

Expand Down Expand Up @@ -1302,7 +1302,7 @@ func (s *state) IsBroken() bool {
return true
default:
}
if err := s.Ping(); err != nil {
if err := s.ping(); err != nil {
logger.Debugf("connection ping failed: %v", err)
return true
}
Expand Down
23 changes: 0 additions & 23 deletions api/apiclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,29 +1127,6 @@ func (s *apiclientSuite) TestAPICallError(c *gc.C) {
c.Check(clock.waits, gc.HasLen, 0)
}

func (s *apiclientSuite) TestPing(c *gc.C) {
clock := &fakeClock{}
rpcConn := newRPCConnection()
conn := api.NewTestingState(api.TestingStateParams{
RPCConnection: rpcConn,
Clock: clock,
})
err := conn.Ping()
c.Assert(err, jc.ErrorIsNil)
rpcConn.stub.CheckCalls(c, []testing.StubCall{{
"Pinger.Ping", []interface{}{0, nil},
}})
}

func (s *apiclientSuite) TestPingBroken(c *gc.C) {
conn := api.NewTestingState(api.TestingStateParams{
RPCConnection: newRPCConnection(errors.New("no biscuit")),
Clock: &fakeClock{},
})
err := conn.Ping()
c.Assert(err, gc.ErrorMatches, "no biscuit")
}

func (s *apiclientSuite) TestIsBrokenOk(c *gc.C) {
conn := api.NewTestingState(api.TestingStateParams{
RPCConnection: newRPCConnection(),
Expand Down
5 changes: 0 additions & 5 deletions api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,6 @@ type Connection interface {
// All the rest are strange and questionable and deserve extra attention
// and/or discussion.

// Ping makes an API request which checks if the connection is
// still functioning.
// NOTE: This method is deprecated. Please use IsBroken or Broken instead.
Ping() error

// I think this is actually dead code. It's tested, at least, so I'm
// keeping it for now, but it's not apparently used anywhere else.
AllFacadeVersions() map[string][]int
Expand Down

0 comments on commit e157566

Please sign in to comment.