| 112 | } |
| 113 | |
| 114 | func TestHTTP2ProtocolSelectorRefresh(t *testing.T) { |
| 115 | fetcher := dynamicMockFetcher{} |
| 116 | // Since the user chooses http2 on purpose, we always stick to it. |
| 117 | selector, err := NewProtocolSelector(HTTP2.String(), testAccountTag, false, fetcher.fetch(), testNoTTL, &log) |
| 118 | require.NoError(t, err) |
| 119 | assert.Equal(t, HTTP2, selector.Current()) |
| 120 | |
| 121 | fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 100}} |
| 122 | assert.Equal(t, HTTP2, selector.Current()) |
| 123 | |
| 124 | fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 0}} |
| 125 | assert.Equal(t, HTTP2, selector.Current()) |
| 126 | |
| 127 | fetcher.err = fmt.Errorf("failed to fetch") |
| 128 | assert.Equal(t, HTTP2, selector.Current()) |
| 129 | |
| 130 | fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: -1}} |
| 131 | fetcher.err = nil |
| 132 | assert.Equal(t, HTTP2, selector.Current()) |
| 133 | |
| 134 | fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 0}} |
| 135 | assert.Equal(t, HTTP2, selector.Current()) |
| 136 | |
| 137 | fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: 100}} |
| 138 | assert.Equal(t, HTTP2, selector.Current()) |
| 139 | |
| 140 | fetcher.protocolPercents = edgediscovery.ProtocolPercents{edgediscovery.ProtocolPercent{Protocol: "http2", Percentage: -1}} |
| 141 | assert.Equal(t, HTTP2, selector.Current()) |
| 142 | } |
| 143 | |
| 144 | func TestAutoProtocolSelectorNoRefreshWithToken(t *testing.T) { |
| 145 | fetcher := dynamicMockFetcher{} |