Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
52e4011a
Unverified
Commit
52e4011a
authored
Mar 25, 2020
by
Zachary Anderson
Committed by
GitHub
Mar 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tool] Timeout the Azure bot detector http request (#53217)
parent
13fa5734
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
bot_detector.dart
packages/flutter_tools/lib/src/base/bot_detector.dart
+10
-2
bot_detector_test.dart
...tter_tools/test/general.shard/base/bot_detector_test.dart
+16
-0
No files found.
packages/flutter_tools/lib/src/base/bot_detector.dart
View file @
52e4011a
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'package:meta/meta.dart'
;
import
'package:platform/platform.dart'
;
...
...
@@ -95,12 +97,14 @@ class AzureDetector {
if
(
_isRunningOnAzure
!=
null
)
{
return
_isRunningOnAzure
;
}
const
Duration
connectionTimeout
=
Duration
(
milliseconds:
250
);
const
Duration
requestTimeout
=
Duration
(
seconds:
1
);
final
HttpClient
client
=
_httpClientFactory
()
..
connectionTimeout
=
con
st
Duration
(
milliseconds:
250
)
;
..
connectionTimeout
=
con
nectionTimeout
;
try
{
final
HttpClientRequest
request
=
await
client
.
getUrl
(
Uri
.
parse
(
_serviceUrl
),
);
)
.
timeout
(
requestTimeout
)
;
request
.
headers
.
add
(
'Metadata'
,
true
);
await
request
.
close
();
}
on
SocketException
{
...
...
@@ -111,6 +115,10 @@ class AzureDetector {
// If the connection gets set up, but encounters an error condition, it
// still means we're on Azure.
return
_isRunningOnAzure
=
true
;
}
on
TimeoutException
{
// 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
;
}
// We got a response. We're running on Azure.
return
_isRunningOnAzure
=
true
;
...
...
packages/flutter_tools/test/general.shard/base/bot_detector_test.dart
View file @
52e4011a
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/bot_detector.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
...
...
@@ -9,6 +11,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import
'package:flutter_tools/src/persistent_tool_state.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:platform/platform.dart'
;
import
'package:quiver/testing/async.dart'
;
import
'../../src/common.dart'
;
import
'../../src/mocks.dart'
;
...
...
@@ -132,6 +135,19 @@ void main() {
expect
(
await
azureDetector
.
isRunningOnAzure
,
isFalse
);
});
testWithoutContext
(
'isRunningOnAzure returns false when the http request times out'
,
()
{
FakeAsync
().
run
((
FakeAsync
time
)
async
{
when
(
mockHttpClient
.
getUrl
(
any
)).
thenAnswer
((
_
)
{
final
Completer
<
HttpClientRequest
>
completer
=
Completer
<
HttpClientRequest
>();
return
completer
.
future
;
// Never completed to test timeout behavior.
});
final
Future
<
bool
>
onBot
=
azureDetector
.
isRunningOnAzure
;
time
.
elapse
(
const
Duration
(
seconds:
2
));
expect
(
await
onBot
,
isFalse
);
});
});
testWithoutContext
(
'isRunningOnAzure returns true when azure metadata is reachable'
,
()
async
{
when
(
mockHttpClient
.
getUrl
(
any
)).
thenAnswer
((
_
)
{
return
Future
<
HttpClientRequest
>.
value
(
mockHttpClientRequest
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment