[flutter_tools] handle OsError thrown during azure detector (#64749)

This commit is contained in:
Jonah Williams
2020-08-27 17:13:04 -07:00
committed by GitHub
parent 36dc3e18ed
commit 5a4fa220e2
2 changed files with 11 additions and 0 deletions

View File

@@ -119,6 +119,9 @@ class AzureDetector {
// The HttpClient connected to a host, but it did not respond in a timely
// fashion. Assume we are not on a bot.
return _isRunningOnAzure = false;
} on OSError {
// The HttpClient might be running in a WSL1 environment.
return _isRunningOnAzure = false;
}
// We got a response. We're running on Azure.
return _isRunningOnAzure = true;

View File

@@ -148,6 +148,14 @@ void main() {
});
});
testWithoutContext('isRunningOnAzure returns false when OsError is thrown', () async {
when(mockHttpClient.getUrl(any)).thenAnswer((_) {
throw const OSError('Connection Refused', 111);
});
expect(await azureDetector.isRunningOnAzure, isFalse);
});
testWithoutContext('isRunningOnAzure returns true when azure metadata is reachable', () async {
when(mockHttpClient.getUrl(any)).thenAnswer((_) {
return Future<HttpClientRequest>.value(mockHttpClientRequest);