go.nanomsg.org/mangos/v3@v3.4.3-0.20240217232803-46464076f1f5/internal/test/maxrx.go (about) 1 /* 2 * Copyright 2019 The Mangos Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use file except in compliance with the License. 6 * You may obtain a copy of the license at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package test 19 20 import ( 21 "testing" 22 "time" 23 24 "go.nanomsg.org/mangos/v3" 25 ) 26 27 // VerifyMaxRx is used to test that the transport enforces the maximum 28 // receive size. In order to avoid challenges, this has to be pair. 29 func VerifyMaxRx(t *testing.T, addr string, makePair func() (mangos.Socket, error)) { 30 maxrx := 100 31 32 rx := GetSocket(t, makePair) 33 defer func() { MustClose(t, rx) }() 34 tx := GetSocket(t, makePair) 35 defer func() { MustClose(t, tx) }() 36 37 // Now try setting the option 38 MustSucceed(t, rx.SetOption(mangos.OptionMaxRecvSize, maxrx)) 39 // At this point, we can issue requests on rq, and read them from rp. 40 MustSucceed(t, rx.SetOption(mangos.OptionRecvDeadline, time.Millisecond*200)) 41 MustSucceed(t, tx.SetOption(mangos.OptionSendDeadline, time.Second)) 42 43 ConnectPairVia(t, addr, rx, tx, nil, nil) 44 45 for i := maxrx - 1; i < maxrx+1; i++ { 46 m := mangos.NewMessage(i) 47 m.Body = append(m.Body, make([]byte, i)...) 48 MustSendMsg(t, tx, m) 49 if i <= maxrx { 50 m = MustRecvMsg(t, rx) 51 m.Free() 52 } else { 53 MustNotRecv(t, rx, mangos.ErrRecvTimeout) 54 } 55 } 56 }