Compare commits

...

11 Commits

Author SHA1 Message Date
Mochi
b08a57eb89 Update Readme 2020-02-12 22:56:49 +00:00
Mochi
e8e29e95cf Update Readme 2020-02-12 22:49:11 +00:00
Mochi
8e468852b2 Update Chart Labels 2020-02-12 22:48:50 +00:00
Mochi
7c23925ec6 Update Readme 2020-02-12 21:59:56 +00:00
Mochi
aa90dd80b3 Update Badges 2020-02-12 21:47:49 +00:00
Mochi
a98e16790b Update Badges 2020-02-12 21:47:21 +00:00
Mochi
bec9401213 Fix test races 2020-02-12 21:15:15 +00:00
Mochi
7103f0439a Update travis 2020-02-12 20:43:11 +00:00
Mochi
b605c94e5b Fix examples 2020-02-12 20:39:30 +00:00
Mochi
31a026b14a Add TravisCI 2020-02-12 20:35:53 +00:00
Mochi
4fdf2ae2fe Add badges 2020-02-12 20:30:17 +00:00
17 changed files with 114 additions and 67 deletions

18
.travis.yml Normal file
View File

@@ -0,0 +1,18 @@
dist: xenial
language: go
env:
- GO111MODULE=on
go:
- 1.13.x
git:
depth: 1
script:
- go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@@ -1,7 +1,18 @@
<p align="center">
[![Build Status](https://travis-ci.com/mochi-co/mqtt.svg?token=59nqixhtefy2iQRwsPcu&branch=master)](https://travis-ci.com/mochi-co/mqtt)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/mochi-co/mqtt/issues)
[![codecov](https://codecov.io/gh/mochi-co/mqtt/branch/master/graph/badge.svg?token=6vBUgYVaVB)](https://codecov.io/gh/mochi-co/mqtt)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b48e17f87cee4221b60a45c02d49148c)](https://www.codacy.com/app/mochi-co/mqtt?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=mochi-co/mqtt&amp;utm_campaign=Badge_Grade)
[![GoDoc](https://godoc.org/github.com/mochi-co/mqtt?status.svg)](https://pkg.go.dev/github.com/mochi-co/mqtt)
</p>
# Mochi MQTT
### A High-performance MQTT server in Go (v3.0 | v3.1.1)
Mochi MQTT is an embeddable high-performance MQTT broker server written in Go, and compliant with the MQTT v3.0 and v3.1.1 specification for the development of IoT and smarthome projects. The server can be used either as a standalone binary or embedded as a library in your own projects. Mochi MQTT message throughput is comparable with world favourites such as Mosquitto, Mosca, and VerneMQ.
Mochi MQTT is an embeddable high-performance MQTT broker server written in Go, and compliant with the MQTT v3.0 and v3.1.1 specification for the development of IoT and smarthome projects. The server can be used either as a standalone binary or embedded as a library in your own projects. Mochi MQTT message throughput is comparable with everyone's favourites such as Mosquitto, Mosca, and VerneMQ.
#### What is MQTT?
MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. [Learn more](https://mqtt.org/faq)
@@ -21,11 +32,12 @@ MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely sim
- MQTT v5 compatibility
#### Performance (messages/second)
Performance benchmarks were tested using [MQTT-Stresser](https://github.com/inovex/mqtt-stresser) on a 13-inch, Early 2015 Macbook Pro (2.7 GHz Intel Core i5). Taking into account bursts of high and low throughput, the median scores are the most useful. Higher is better.
Performance benchmarks were tested using [MQTT-Stresser](https://github.com/inovex/mqtt-stresser) on a 13-inch, Early 2015 Macbook Pro (2.7 GHz Intel Core i5). Taking into account bursts of high and low throughput, the median scores are the most useful. Higher is better. SEND = Publish throughput, RECV = Subscribe throughput.
> As usual, any performance benchmarks should be taken with a pinch of salt, but are shown to demonstrate typical throughput compared to the other leading MQTT brokers.
**Single Client, 10,000 messages**
_With only 1 client, there is no variation in throughput so the benchmark is reports the same number for high, low, and median._
![1 Client, 10,000 Messages](assets/benchmarkchart_1_10000.png "1 Client, 10,000 Messages")
@@ -33,11 +45,11 @@ Performance benchmarks were tested using [MQTT-Stresser](https://github.com/inov
| | Mochi | Mosquitto | EMQX | VerneMQ | Mosca |
| :----------- | --------: | ----------: | -------: | --------: | --------:
| SEND High | 36505 | 30597 | 27202 | 32782 | 30125 |
| SEND Low | 36505 | 30597 | 27202 | 32782 | 30125 |
| SEND Max | 36505 | 30597 | 27202 | 32782 | 30125 |
| SEND Min | 36505 | 30597 | 27202 | 32782 | 30125 |
| SEND Median | 36505 | 30597 | 27202 |32782 | 30125 |
| RECV High | 152221 | 59130 | 7879 | 17551 | 9145 |
| RECV Low | 152221 | 59130 | 7879 | 17551 | 9145 |
| RECV Max | 152221 | 59130 | 7879 | 17551 | 9145 |
| RECV Min | 152221 | 59130 | 7879 | 17551 | 9145 |
| RECV Median | 152221 | 59130 | 7879 | 17551 | 9145 |
**10 Clients, 1,000 Messages**
@@ -48,11 +60,11 @@ Performance benchmarks were tested using [MQTT-Stresser](https://github.com/inov
| | Mochi | Mosquitto | EMQX | VerneMQ | Mosca |
| :----------- | --------: | ----------: | -------: | --------: | --------:
| SEND High | 37193 | 15775 | 17455 | 34138 | 36575 |
| SEND Low | 6529 | 6446 | 7714 | 8583 | 7383 |
| SEND Max | 37193 | 15775 | 17455 | 34138 | 36575 |
| SEND Min | 6529 | 6446 | 7714 | 8583 | 7383 |
| SEND Median | 15127 | 7813 | 10305 | 9887 | 8169 |
| RECV High | 33535 | 3710 | 3022 | 4534 | 9411 |
| RECV Low | 7484 | 2661 | 1689 | 2021 | 2275 |
| RECV Max | 33535 | 3710 | 3022 | 4534 | 9411 |
| RECV Min | 7484 | 2661 | 1689 | 2021 | 2275 |
| RECV Median | 11427 | 3142 | 1831 | 2468 | 4692 |
**10 Clients, 10,000 Messages**
@@ -63,11 +75,11 @@ Performance benchmarks were tested using [MQTT-Stresser](https://github.com/inov
| | Mochi | Mosquitto | EMQX | VerneMQ | Mosca |
| :----------- | --------: | ----------: | -------: | --------: | --------:
| SEND High | 13153 | 13270 | 12229 | 13025 | 38446 |
| SEND Low | 8728 | 8513 | 8193 | 6483 | 3889 |
| SEND Max | 13153 | 13270 | 12229 | 13025 | 38446 |
| SEND Min | 8728 | 8513 | 8193 | 6483 | 3889 |
| SEND Median | 9045 | 9532 | 9252 | 8031 | 9210 |
| RECV High | 20774 | 5052 | 2093 | 2071 | 43008 |
| RECV Low | 10718 |3995 | 1531 | 1673 | 18764 |
| RECV Max | 20774 | 5052 | 2093 | 2071 | 43008 |
| RECV Min | 10718 |3995 | 1531 | 1673 | 18764 |
| RECV Median | 16339 | 4607 | 1620 | 1907 | 33524 |
**500 Clients, 100 Messages**
@@ -78,11 +90,11 @@ Performance benchmarks were tested using [MQTT-Stresser](https://github.com/inov
| | Mochi | Mosquitto | EMQX | VerneMQ | Mosca |
| :----------- | --------: | ----------: | -------: | --------: | --------:
| SEND High | 70688 | 72686 | 71392 | 75336 | 73192 |
| SEND Low | 1021 | 2577 | 1603 | 8417 | 2344 |
| SEND Max | 70688 | 72686 | 71392 | 75336 | 73192 |
| SEND Min | 1021 | 2577 | 1603 | 8417 | 2344 |
| SEND Median | 49871 | 33076 | 33637 | 35200 | 31312 |
| RECV High | 116163 | 4215 | 3427 | 5484 | 10100 |
| RECV Low | 1044 | 156 | 56 | 83 | 169 |
| RECV Max | 116163 | 4215 | 3427 | 5484 | 10100 |
| RECV Min | 1044 | 156 | 56 | 83 | 169 |
| RECV Median | 24398 | 208 | 94 | 413 | 474 |
#### Using the Broker

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

@@ -27,7 +27,7 @@ func main() {
server := mqtt.New()
stats := listeners.NewHTTPStats("stats", ":8080")
err = server.AddListener(stats, nil)
err := server.AddListener(stats, nil)
if err != nil {
log.Fatal(err)
}

View File

@@ -6,12 +6,14 @@ import (
"os"
"os/signal"
"syscall"
"time"
"github.com/logrusorgru/aurora"
"go.etcd.io/bbolt"
mqtt "github.com/mochi-co/mqtt/server"
"github.com/mochi-co/mqtt/server/listeners"
"github.com/mochi-co/mqtt/server/listeners/auth"
"github.com/mochi-co/mqtt/server/persistence/bolt"
)
@@ -29,7 +31,7 @@ func main() {
server := mqtt.New()
tcp := listeners.NewTCP("t1", ":1883")
err := server.AddListener(tcp, &listeners.Config{
Auth: new(Auth),
Auth: new(auth.Allow),
})
if err != nil {
log.Fatal(err)

View File

@@ -11,6 +11,7 @@ import (
mqtt "github.com/mochi-co/mqtt/server"
"github.com/mochi-co/mqtt/server/listeners"
"github.com/mochi-co/mqtt/server/listeners/auth"
)
func main() {
@@ -27,7 +28,7 @@ func main() {
server := mqtt.New()
tcp := listeners.NewTCP("t1", ":1883")
err := server.AddListener(tcp, &listeners.Config{
Auth: new(Auth),
Auth: new(auth.Allow),
})
if err != nil {
log.Fatal(err)

View File

@@ -26,7 +26,7 @@ func main() {
server := mqtt.New()
ws := listeners.NewWebsocket("ws1", ":1882")
err = server.AddListener(ws, nil)
err := server.AddListener(ws, nil)
if err != nil {
log.Fatal(err)
}

3
go.mod
View File

@@ -7,12 +7,9 @@ require (
github.com/asdine/storm/v3 v3.1.0
github.com/gorilla/websocket v1.4.1
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/krylovsk/mqtt-benchmark v0.1.1 // indirect
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23
github.com/rs/xid v1.2.1
github.com/stretchr/testify v1.4.0
go.etcd.io/bbolt v1.3.3
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
)
replace github.com/mochi-co/debug => /Users/mochimochi/Development/Go/src/github.com/mochi-co/debug

7
go.sum
View File

@@ -1,7 +1,5 @@
github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/GaryBoone/GoStats v0.0.0-20130122001700-1993eafbef57 h1:EUQH/F+mzJBs53c75r7R5zdM/kz7BHXoWBFsVXzadVw=
github.com/GaryBoone/GoStats v0.0.0-20130122001700-1993eafbef57/go.mod h1:5zDl2HgTb/k5i9op9y6IUSiuVkZFpUrWGQbZc9tNR40=
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863 h1:BRrxwOZBolJN4gIwvZMJY1tzqBvQgpaZiQRuIDD40jM=
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM=
github.com/asdine/storm v2.1.2+incompatible h1:dczuIkyqwY2LrtXPz8ixMrU/OFgZp71kbKTHGrXYt/Q=
@@ -12,8 +10,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.2.0 h1:1F8mhG9+aO5/xpdtFkW4SxOJB67ukuDC3t2y2qayIX0=
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -28,8 +24,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/krylovsk/mqtt-benchmark v0.1.1 h1:ErPkllMHrX5dAGzWBNH+yYLY/kIufGEBWOPOmOSilmg=
github.com/krylovsk/mqtt-benchmark v0.1.1/go.mod h1:ud2sw14D+GdIeJGOh9ZZnBfjAVXzPyHQl58Yagk5P9w=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23 h1:Wp7NjqGKGN9te9N/rvXYRhlVcrulGdxnz8zadXWs7fc=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -46,7 +40,6 @@ go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

View File

@@ -56,8 +56,8 @@ func TestGetPos(t *testing.T) {
require.Equal(t, int64(0), tail)
require.Equal(t, int64(0), head)
buf.tail = 3
buf.head = 11
atomic.StoreInt64(&buf.tail, 3)
atomic.StoreInt64(&buf.head, 11)
tail, head = buf.GetPos()
require.Equal(t, int64(3), tail)
@@ -75,12 +75,12 @@ func TestGet(t *testing.T) {
func TestSetPos(t *testing.T) {
buf := NewBuffer(16, 4)
require.Equal(t, int64(0), buf.tail)
require.Equal(t, int64(0), buf.head)
require.Equal(t, int64(0), atomic.LoadInt64(&buf.tail))
require.Equal(t, int64(0), atomic.LoadInt64(&buf.head))
buf.SetPos(4, 8)
require.Equal(t, int64(4), buf.tail)
require.Equal(t, int64(8), buf.head)
require.Equal(t, int64(4), atomic.LoadInt64(&buf.tail))
require.Equal(t, int64(8), atomic.LoadInt64(&buf.head))
}
func TestSet(t *testing.T) {
@@ -268,7 +268,7 @@ func TestCommitTail(t *testing.T) {
buf.wcond.Broadcast()
buf.wcond.L.Unlock()
}
require.Equal(t, tt.next, buf.tail, "Next tail mismatch [i:%d] %s", i, tt.desc)
require.Equal(t, tt.next, atomic.LoadInt64(&buf.tail), "Next tail mismatch [i:%d] %s", i, tt.desc)
}
}

View File

@@ -125,10 +125,10 @@ func TestServeListener(t *testing.T) {
l.Add(NewMockListener("t1", ":1882"))
l.Serve("t1", MockEstablisher)
time.Sleep(time.Millisecond)
require.Equal(t, true, l.internal["t1"].(*MockListener).IsServing)
require.Equal(t, true, l.internal["t1"].(*MockListener).IsServing())
l.Close("t1", MockCloser)
require.Equal(t, false, l.internal["t1"].(*MockListener).IsServing)
require.Equal(t, false, l.internal["t1"].(*MockListener).IsServing())
}
func BenchmarkServeListener(b *testing.B) {
@@ -147,17 +147,17 @@ func TestServeAllListeners(t *testing.T) {
l.ServeAll(MockEstablisher)
time.Sleep(time.Millisecond)
require.Equal(t, true, l.internal["t1"].(*MockListener).IsServing)
require.Equal(t, true, l.internal["t2"].(*MockListener).IsServing)
require.Equal(t, true, l.internal["t3"].(*MockListener).IsServing)
require.Equal(t, true, l.internal["t1"].(*MockListener).IsServing())
require.Equal(t, true, l.internal["t2"].(*MockListener).IsServing())
require.Equal(t, true, l.internal["t3"].(*MockListener).IsServing())
l.Close("t1", MockCloser)
l.Close("t2", MockCloser)
l.Close("t3", MockCloser)
require.Equal(t, false, l.internal["t1"].(*MockListener).IsServing)
require.Equal(t, false, l.internal["t2"].(*MockListener).IsServing)
require.Equal(t, false, l.internal["t3"].(*MockListener).IsServing)
require.Equal(t, false, l.internal["t1"].(*MockListener).IsServing())
require.Equal(t, false, l.internal["t2"].(*MockListener).IsServing())
require.Equal(t, false, l.internal["t3"].(*MockListener).IsServing())
}
func BenchmarkServeAllListeners(b *testing.B) {
@@ -201,9 +201,9 @@ func TestCloseAllListeners(t *testing.T) {
l.Add(NewMockListener("t3", ":1882"))
l.ServeAll(MockEstablisher)
time.Sleep(time.Millisecond)
require.Equal(t, true, l.internal["t1"].(*MockListener).IsServing)
require.Equal(t, true, l.internal["t2"].(*MockListener).IsServing)
require.Equal(t, true, l.internal["t3"].(*MockListener).IsServing)
require.Equal(t, true, l.internal["t1"].(*MockListener).IsServing())
require.Equal(t, true, l.internal["t2"].(*MockListener).IsServing())
require.Equal(t, true, l.internal["t3"].(*MockListener).IsServing())
closed := make(map[string]bool)
l.CloseAll(func(id string) {

View File

@@ -21,13 +21,13 @@ func MockEstablisher(id string, c net.Conn, ac auth.Controller) error {
// MockListener is a mock listener for establishing client connections.
type MockListener struct {
sync.RWMutex
id string // the id of the listener.
Config *Config // configuration for the listener.
address string // the network address the listener binds to.
IsListening bool // indiciate the listener is listening.
IsServing bool // indicate the listener is serving.
done chan bool // indicate the listener is done.
ErrListen bool // throw an error on listen.
id string // the id of the listener.
Config *Config // configuration for the listener.
address string // the network address the listener binds to.
Listening bool // indiciate the listener is listening.
Serving bool // indicate the listener is serving.
done chan bool // indicate the listener is done.
ErrListen bool // throw an error on listen.
}
// NewMockListener returns a new instance of MockListener
@@ -42,7 +42,7 @@ func NewMockListener(id, address string) *MockListener {
// Serve serves the mock listener.
func (l *MockListener) Serve(establisher EstablishFunc) {
l.Lock()
l.IsServing = true
l.Serving = true
l.Unlock()
for {
select {
@@ -59,7 +59,7 @@ func (l *MockListener) Listen(s *system.Info) error {
}
l.Lock()
l.IsListening = true
l.Listening = true
l.Unlock()
return nil
}
@@ -83,7 +83,21 @@ func (l *MockListener) ID() string {
func (l *MockListener) Close(closer CloseFunc) {
l.Lock()
defer l.Unlock()
l.IsServing = false
l.Serving = false
closer(l.id)
close(l.done)
}
// IsServing indicates whether the mock listener is serving.
func (l *MockListener) IsServing() bool {
l.Lock()
defer l.Unlock()
return l.Serving
}
// IsServing indicates whether the mock listener is listening.
func (l *MockListener) IsListening() bool {
l.Lock()
defer l.Unlock()
return l.Listening
}

View File

@@ -28,10 +28,10 @@ func TestNewMockListenerListen(t *testing.T) {
require.Equal(t, "t1", mocked.id)
require.Equal(t, ":1882", mocked.address)
require.Equal(t, false, mocked.IsListening)
require.Equal(t, false, mocked.IsListening())
err := mocked.Listen(nil)
require.NoError(t, err)
require.Equal(t, true, mocked.IsListening)
require.Equal(t, true, mocked.IsListening())
}
func TestNewMockListenerListenFailure(t *testing.T) {
mocked := NewMockListener("t1", ":1882")
@@ -42,7 +42,7 @@ func TestNewMockListenerListenFailure(t *testing.T) {
func TestMockListenerServe(t *testing.T) {
mocked := NewMockListener("t1", ":1882")
require.Equal(t, false, mocked.IsServing)
require.Equal(t, false, mocked.IsServing())
o := make(chan bool)
go func(o chan bool) {
@@ -51,7 +51,7 @@ func TestMockListenerServe(t *testing.T) {
}(o)
time.Sleep(time.Millisecond) // easy non-channel wait for start of serving
require.Equal(t, true, mocked.IsServing)
require.Equal(t, true, mocked.IsServing())
var closed bool
mocked.Close(func(id string) {
@@ -77,3 +77,13 @@ func TestMockListenerClose(t *testing.T) {
})
require.Equal(t, true, closed)
}
func TestNewMockListenerIsListening(t *testing.T) {
mocked := NewMockListener("t1", ":1882")
require.Equal(t, false, mocked.IsListening())
}
func TestNewMockListenerIsServing(t *testing.T) {
mocked := NewMockListener("t1", ":1882")
require.Equal(t, false, mocked.IsServing())
}

View File

@@ -134,7 +134,7 @@ func TestServerServe(t *testing.T) {
require.Equal(t, 1, s.Listeners.Len())
listener, ok := s.Listeners.Get("t1")
require.Equal(t, true, ok)
require.Equal(t, true, listener.(*listeners.MockListener).IsServing)
require.Equal(t, true, listener.(*listeners.MockListener).IsServing())
}
func TestServerServeFail(t *testing.T) {
@@ -1195,11 +1195,11 @@ func TestServerClose(t *testing.T) {
listener, ok := s.Listeners.Get("t1")
require.Equal(t, true, ok)
require.Equal(t, true, listener.(*listeners.MockListener).IsServing)
require.Equal(t, true, listener.(*listeners.MockListener).IsServing())
s.Close()
time.Sleep(time.Millisecond)
require.Equal(t, false, listener.(*listeners.MockListener).IsServing)
require.Equal(t, false, listener.(*listeners.MockListener).IsServing())
require.Equal(t, true, p.Closed)
}