(t *testing.T)
| 179 | } |
| 180 | |
| 181 | func TestNetworkTelemetryBatcher(t *testing.T) { |
| 182 | t.Parallel() |
| 183 | |
| 184 | var ( |
| 185 | events = make(chan []*proto.TelemetryEvent, 64) |
| 186 | mClock = quartz.NewMock(t) |
| 187 | b = tailnet.NewNetworkTelemetryBatcher(mClock, time.Millisecond, 3, func(batch []*proto.TelemetryEvent) { |
| 188 | assert.LessOrEqual(t, len(batch), 3) |
| 189 | events <- batch |
| 190 | }) |
| 191 | ) |
| 192 | |
| 193 | b.Handler([]*proto.TelemetryEvent{ |
| 194 | {Id: []byte("1")}, |
| 195 | {Id: []byte("2")}, |
| 196 | }) |
| 197 | b.Handler([]*proto.TelemetryEvent{ |
| 198 | {Id: []byte("3")}, |
| 199 | {Id: []byte("4")}, |
| 200 | }) |
| 201 | |
| 202 | // Should overflow and send a batch. |
| 203 | ctx := testutil.Context(t, testutil.WaitShort) |
| 204 | batch := testutil.TryReceive(ctx, t, events) |
| 205 | require.Len(t, batch, 3) |
| 206 | require.Equal(t, "1", string(batch[0].Id)) |
| 207 | require.Equal(t, "2", string(batch[1].Id)) |
| 208 | require.Equal(t, "3", string(batch[2].Id)) |
| 209 | |
| 210 | // Should send any pending events when the ticker fires. |
| 211 | mClock.Advance(time.Millisecond) |
| 212 | batch = testutil.TryReceive(ctx, t, events) |
| 213 | require.Len(t, batch, 1) |
| 214 | require.Equal(t, "4", string(batch[0].Id)) |
| 215 | |
| 216 | // Should send any pending events when closed. |
| 217 | b.Handler([]*proto.TelemetryEvent{ |
| 218 | {Id: []byte("5")}, |
| 219 | {Id: []byte("6")}, |
| 220 | }) |
| 221 | err := b.Close() |
| 222 | require.NoError(t, err) |
| 223 | batch = testutil.TryReceive(ctx, t, events) |
| 224 | require.Len(t, batch, 2) |
| 225 | require.Equal(t, "5", string(batch[0].Id)) |
| 226 | require.Equal(t, "6", string(batch[1].Id)) |
| 227 | } |
| 228 | |
| 229 | func TestClientUserCoordinateeAuth(t *testing.T) { |
| 230 | t.Parallel() |
nothing calls this directly
no test coverage detected