MCPcopy Create free account
hub / github.com/AdRoll/baker / TestTCPChunks

Function TestTCPChunks

input/tcp_test.go:101–188  ·  view source on GitHub ↗

This test checks that, given a reasonable amount of time (500ms) and under normal conditions, all log lines sent by chunk on the TCP socket are received by the output.

(t *testing.T)

Source from the content-addressed store, hash-verified

99// normal conditions, all log lines sent by chunk on the TCP socket are
100// received by the output.
101func TestTCPChunks(t *testing.T) {
102 toml := `
103 [fields]
104 names = ["f0", "f1", "f2"]
105
106 [input]
107 name="TCP"
108
109 [output]
110 name="RawRecorder"
111 procs=1
112 `
113 c := baker.Components{
114 Inputs: []baker.InputDesc{TCPDesc},
115 Outputs: []baker.OutputDesc{outputtest.RawRecorderDesc},
116 }
117
118 cfg, err := baker.NewConfigFromToml(strings.NewReader(toml), c)
119 if err != nil {
120 t.Error(err)
121 }
122
123 topology, err := baker.NewTopologyFromConfig(cfg)
124 if err != nil {
125 t.Error(err)
126 }
127 topology.Start()
128 // Give baker some time to start the tcp server
129 time.Sleep(500 * time.Millisecond)
130
131 const (
132 nchunks = 100 // num lines fed
133 chunksize = 37 // chunk size
134 )
135
136 errc := make(chan error, 1)
137 go func() {
138 conn, err := net.Dial("tcp", ":6000")
139 if err != nil {
140 errc <- err
141 return
142 }
143 defer conn.Close()
144
145 w := gzip.NewWriter(conn)
146 defer w.Close()
147
148 buf := &bytes.Buffer{}
149
150 for i := 0; i < nchunks; i++ {
151 buf.Reset()
152 for j := 0; j < chunksize; j++ {
153 l := baker.LogLine{FieldSeparator: baker.DefaultLogLineFieldSeparator}
154 l.Set(1, []byte("field"))
155 buf.Write(l.ToText(nil))
156 buf.WriteByte('\n')
157 if _, err := buf.WriteTo(w); err != nil {
158 errc <- err

Callers

nothing calls this directly

Calls 12

SetMethod · 0.95
ToTextMethod · 0.95
NewConfigFromTomlFunction · 0.92
NewTopologyFromConfigFunction · 0.92
ResetMethod · 0.80
CloseMethod · 0.65
StopMethod · 0.65
ErrorMethod · 0.45
StartMethod · 0.45
WriteMethod · 0.45
FlushMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected