TestWRR_Metrics_SubConnWeight tests different scenarios for the weight call on a weighted SubConn, and expects certain metrics for each of these scenarios.
(t *testing.T)
| 39 | // on a weighted SubConn, and expects certain metrics for each of these |
| 40 | // scenarios. |
| 41 | func (s) TestWRR_Metrics_SubConnWeight(t *testing.T) { |
| 42 | tests := []struct { |
| 43 | name string |
| 44 | weightExpirationPeriod time.Duration |
| 45 | blackoutPeriod time.Duration |
| 46 | lastUpdated time.Time |
| 47 | nonEmpty time.Time |
| 48 | nowTime time.Time |
| 49 | endpointWeightStaleWant float64 |
| 50 | endpointWeightNotYetUsableWant float64 |
| 51 | endpointWeightWant float64 |
| 52 | }{ |
| 53 | // The weighted SubConn's lastUpdated field hasn't been set, so this |
| 54 | // SubConn's weight is not yet usable. Thus, should emit that endpoint |
| 55 | // weight is not yet usable, and 0 for weight. |
| 56 | { |
| 57 | name: "no weight set", |
| 58 | weightExpirationPeriod: time.Second, |
| 59 | blackoutPeriod: time.Second, |
| 60 | nowTime: time.Now(), |
| 61 | endpointWeightStaleWant: 0, |
| 62 | endpointWeightNotYetUsableWant: 1, |
| 63 | endpointWeightWant: 0, |
| 64 | }, |
| 65 | { |
| 66 | name: "weight expiration", |
| 67 | lastUpdated: time.Now(), |
| 68 | weightExpirationPeriod: 2 * time.Second, |
| 69 | blackoutPeriod: time.Second, |
| 70 | nowTime: time.Now().Add(100 * time.Second), |
| 71 | endpointWeightStaleWant: 1, |
| 72 | endpointWeightNotYetUsableWant: 0, |
| 73 | endpointWeightWant: 0, |
| 74 | }, |
| 75 | { |
| 76 | name: "in blackout period", |
| 77 | lastUpdated: time.Now(), |
| 78 | weightExpirationPeriod: time.Minute, |
| 79 | blackoutPeriod: 10 * time.Second, |
| 80 | nowTime: time.Now(), |
| 81 | endpointWeightStaleWant: 0, |
| 82 | endpointWeightNotYetUsableWant: 1, |
| 83 | endpointWeightWant: 0, |
| 84 | }, |
| 85 | { |
| 86 | name: "normal weight", |
| 87 | lastUpdated: time.Now(), |
| 88 | nonEmpty: time.Now(), |
| 89 | weightExpirationPeriod: time.Minute, |
| 90 | blackoutPeriod: time.Second, |
| 91 | nowTime: time.Now().Add(10 * time.Second), |
| 92 | endpointWeightStaleWant: 0, |
| 93 | endpointWeightNotYetUsableWant: 0, |
| 94 | endpointWeightWant: 3, |
| 95 | }, |
| 96 | { |
| 97 | name: "weight expiration takes precdedence over blackout", |
| 98 | lastUpdated: time.Now(), |