(t *testing.T)
| 112 | } |
| 113 | |
| 114 | func TestSamplerTicking(t *testing.T) { |
| 115 | // Ensure that we're resetting the sampler's counter every tick. |
| 116 | sampler, logs := fakeSampler(DebugLevel, 10*time.Millisecond, 5, 10) |
| 117 | |
| 118 | // If we log five or fewer messages every tick, none of them should be |
| 119 | // dropped. |
| 120 | for tick := 0; tick < 2; tick++ { |
| 121 | for i := 1; i <= 5; i++ { |
| 122 | writeSequence(sampler, i, InfoLevel) |
| 123 | } |
| 124 | ztest.Sleep(15 * time.Millisecond) |
| 125 | } |
| 126 | assertSequence( |
| 127 | t, |
| 128 | logs.TakeAll(), |
| 129 | InfoLevel, |
| 130 | 1, 2, 3, 4, 5, // first tick |
| 131 | 1, 2, 3, 4, 5, // second tick |
| 132 | ) |
| 133 | |
| 134 | // If we log quickly, we should drop some logs. The first five statements |
| 135 | // each tick should be logged, then every tenth. |
| 136 | for tick := 0; tick < 3; tick++ { |
| 137 | for i := 1; i < 18; i++ { |
| 138 | writeSequence(sampler, i, InfoLevel) |
| 139 | } |
| 140 | ztest.Sleep(10 * time.Millisecond) |
| 141 | } |
| 142 | |
| 143 | assertSequence( |
| 144 | t, |
| 145 | logs.TakeAll(), |
| 146 | InfoLevel, |
| 147 | 1, 2, 3, 4, 5, 15, // first tick |
| 148 | 1, 2, 3, 4, 5, 15, // second tick |
| 149 | 1, 2, 3, 4, 5, 15, // third tick |
| 150 | ) |
| 151 | } |
| 152 | |
| 153 | type countingCore struct { |
| 154 | logs atomic.Uint32 |
nothing calls this directly
no test coverage detected