Skip to content

Commit

Permalink
Merge cbbffa7 into 3c5fc68
Browse files Browse the repository at this point in the history
  • Loading branch information
tylertreat committed Jun 29, 2016
2 parents 3c5fc68 + cbbffa7 commit 2f2446e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions stan.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Conn interface {

// Close
Close() error

// Status returns the status of the underlying NATS conn.
Status() nats.Status
}

// Errors
Expand Down Expand Up @@ -271,6 +274,14 @@ func (sc *conn) Close() error {
return nil
}

// Status returns the status of the underlying NATS conn.
func (sc *conn) Status() nats.Status {
if sc.nc == nil {
return nats.CLOSED
}
return sc.nc.Status()
}

// Process a heartbeat from the NATS Streaming cluster
func (sc *conn) processHeartBeat(m *nats.Msg) {
// No payload assumed, just reply.
Expand Down
16 changes: 16 additions & 0 deletions stan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,3 +1853,19 @@ func TestRaceAckOnClose(t *testing.T) {
time.Sleep(10 * time.Millisecond)
sc.Close()
}

func TestStatus(t *testing.T) {
s := RunServer(clusterName)
defer s.Shutdown()

sc := NewDefaultConnection(t)
defer sc.Close()

if sc.Status() != nats.CONNECTED {
t.Fatal("Should have status set to CONNECTED")
}
sc.Close()
if sc.Status() != nats.CLOSED {
t.Fatal("Should have status set to CLOSED")
}
}

0 comments on commit 2f2446e

Please sign in to comment.