github.com/gdamore/mangos@v1.4.0/test/busnonblock_test.go (about) 1 // Copyright 2016 The Mangos Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use file except in compliance with the License. 5 // You may obtain a copy of the license at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package test 16 17 import ( 18 "testing" 19 "time" 20 21 "nanomsg.org/go-mangos" 22 "nanomsg.org/go-mangos/protocol/bus" 23 "nanomsg.org/go-mangos/transport/tcp" 24 25 . "github.com/smartystreets/goconvey/convey" 26 ) 27 28 func testBusNonBlock(addr string, tran mangos.Transport) { 29 maxqlen := 2 30 timeout := time.Second / 10 31 32 Convey("Given a suitable Bus socket", func() { 33 rp, err := bus.NewSocket() 34 So(err, ShouldBeNil) 35 So(rp, ShouldNotBeNil) 36 37 defer rp.Close() 38 rp.AddTransport(tran) 39 40 err = rp.SetOption(mangos.OptionWriteQLen, maxqlen) 41 So(err, ShouldBeNil) 42 43 err = rp.SetOption(mangos.OptionSendDeadline, timeout) 44 So(err, ShouldBeNil) 45 46 err = rp.Listen(addr) 47 So(err, ShouldBeNil) 48 49 msg := []byte{'A', 'B', 'C'} 50 51 Convey("We don't block, even sending many messages", func() { 52 for i := 0; i < maxqlen*10; i++ { 53 err := rp.Send(msg) 54 So(err, ShouldBeNil) 55 } 56 }) 57 }) 58 } 59 60 func TestBusNonBlockTCP(t *testing.T) { 61 Convey("Testing Bus Send (TCP) is Non-Blocking", t, func() { 62 testBusNonBlock(AddrTestTCP, tcp.NewTransport()) 63 }) 64 }