MCPcopy
hub / github.com/mochi-mqtt/server / TestClientWritePacketBuffer

Function TestClientWritePacketBuffer

clients_test.go:761–839  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

759}
760
761func TestClientWritePacketBuffer(t *testing.T) {
762 r, w := net.Pipe()
763
764 cl := newClient(w, &ops{
765 info: new(system.Info),
766 hooks: new(Hooks),
767 log: logger,
768 options: &Options{
769 Capabilities: &Capabilities{
770 ReceiveMaximum: 10,
771 TopicAliasMaximum: 10000,
772 MaximumClientWritesPending: 3,
773 maximumPacketID: 10,
774 },
775 },
776 })
777
778 cl.ID = "mochi"
779 cl.State.Inflight.maximumSendQuota = 5
780 cl.State.Inflight.sendQuota = 5
781 cl.State.Inflight.maximumReceiveQuota = 10
782 cl.State.Inflight.receiveQuota = 10
783 cl.Properties.Props.TopicAliasMaximum = 0
784 cl.Properties.Props.RequestResponseInfo = 0x1
785
786 cl.ops.options.ClientNetWriteBufferSize = 10
787 defer cl.Stop(errClientStop)
788
789 small := packets.TPacketData[packets.Publish].Get(packets.TPublishNoPayload).Packet
790 large := packets.TPacketData[packets.Publish].Get(packets.TPublishBasic).Packet
791
792 cl.State.outbound <- small
793
794 tt := []struct {
795 pks []*packets.Packet
796 size int
797 }{
798 {
799 pks: []*packets.Packet{small, small},
800 size: 18,
801 },
802 {
803 pks: []*packets.Packet{large},
804 size: 20,
805 },
806 {
807 pks: []*packets.Packet{small},
808 size: 0,
809 },
810 }
811
812 go func() {
813 for i, tx := range tt {
814 for _, pk := range tx.pks {
815 cl.Properties.ProtocolVersion = pk.ProtocolVersion
816 err := cl.WritePacket(*pk)
817 require.NoError(t, err, "index: %d", i)
818 if i == len(tt)-1 {

Callers

nothing calls this directly

Calls 5

newClientFunction · 0.85
WritePacketMethod · 0.80
StopMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected