github.com/gdamore/mangos@v1.4.0/test/survnonblock_test.go (about) 1 // Copyright 2018 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/surveyor" 23 "nanomsg.org/go-mangos/transport/tcp" 24 25 . "github.com/smartystreets/goconvey/convey" 26 ) 27 28 func testSurvNonBlock(addr string, tran mangos.Transport) { 29 maxqlen := 2 30 timeout := time.Second / 10 31 32 Convey("Given a suitable Surveyor socket", func() { 33 rp, err := surveyor.NewSocket() 34 So(err, ShouldBeNil) 35 So(rp, ShouldNotBeNil) 36 defer rp.Close() 37 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 54 err := rp.Send(msg) 55 So(err, ShouldBeNil) 56 } 57 }) 58 }) 59 } 60 61 func TestSurveyorNonBlockTCP(t *testing.T) { 62 Convey("Testing Survey Send (TCP) is Non-Blocking", t, func() { 63 testSurvNonBlock(AddrTestTCP, tcp.NewTransport()) 64 }) 65 }