(b *testing.B)
| 113 | } |
| 114 | |
| 115 | func BenchmarkPublishProtobufStruct(b *testing.B) { |
| 116 | // stop benchmark for set-up |
| 117 | b.StopTimer() |
| 118 | |
| 119 | s := RunServerOnPort(TEST_PORT) |
| 120 | defer s.Shutdown() |
| 121 | |
| 122 | ec := NewProtoEncodedConn(b) |
| 123 | defer ec.Close() |
| 124 | ch := make(chan bool) |
| 125 | |
| 126 | me := &pb.Person{Name: "derek", Age: 22, Address: "140 New Montgomery St"} |
| 127 | me.Children = make(map[string]*pb.Person) |
| 128 | |
| 129 | me.Children["sam"] = &pb.Person{Name: "sam", Age: 19, Address: "140 New Montgomery St"} |
| 130 | me.Children["meg"] = &pb.Person{Name: "meg", Age: 17, Address: "140 New Montgomery St"} |
| 131 | |
| 132 | ec.Subscribe("protobuf_test", func(p *pb.Person) { |
| 133 | if !reflect.DeepEqual(p, me) { |
| 134 | b.Fatalf("Did not receive the correct protobuf response") |
| 135 | } |
| 136 | ch <- true |
| 137 | }) |
| 138 | |
| 139 | // resume benchmark |
| 140 | b.StartTimer() |
| 141 | |
| 142 | for n := 0; n < b.N; n++ { |
| 143 | ec.Publish("protobuf_test", me) |
| 144 | if e := Wait(ch); e != nil { |
| 145 | b.Fatal("Did not receive the message") |
| 146 | } |
| 147 | } |
| 148 | } |
nothing calls this directly
no test coverage detected