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)
| 99 | // normal conditions, all log lines sent by chunk on the TCP socket are |
| 100 | // received by the output. |
| 101 | func 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 |
nothing calls this directly
no test coverage detected