Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit c38397b

Browse files
author
J Wyman
authored
Merge pull request #701 from whoisj/fix-bitbucket-test
bitbucket: make very slow test fast
2 parents 6239316 + 3709b50 commit c38397b

File tree

3 files changed

+187
-10
lines changed

3 files changed

+187
-10
lines changed
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
using System;
22
using System.Linq;
3-
using Atlassian.Bitbucket.Authentication;
3+
using System.Threading;
4+
using System.Threading.Tasks;
45
using Microsoft.Alm.Authentication;
6+
using Microsoft.Alm.Authentication.Test;
57
using Xunit;
68

79
namespace Atlassian.Bitbucket.Authentication.Test
810
{
9-
public class AuthorityTest
11+
public class AuthorityTest : UnitTestBase
1012
{
13+
public AuthorityTest(Xunit.Abstractions.ITestOutputHelper output)
14+
: base(XunitHelper.Convert(output))
15+
{ }
16+
1117
[Fact]
1218
public void VerifyAcquireTokenAcceptsValidAuthenticationResultTypes()
1319
{
14-
var context = RuntimeContext.Default;
15-
var authority = new Authority(context);
20+
InitializeTest();
21+
22+
var authority = new Authority(Context);
1623
var targetUri = new TargetUri("https://bitbucket.org");
1724
var credentials = new Credential("a", "b");
1825
var resultType = AuthenticationResultType.None;
19-
var tokenScope = Atlassian.Bitbucket.Authentication.TokenScope.None;
26+
var tokenScope = TokenScope.None;
2027

21-
var values = Enum.GetValues(typeof(AuthenticationResultType)).Cast<AuthenticationResultType>();
22-
values.ToList().ForEach(async _ =>
28+
var values = Enum.GetValues(typeof(AuthenticationResultType))
29+
.Cast<AuthenticationResultType>()
30+
.ToList();
31+
int count = 0;
32+
33+
values.ToList().ForEach(_ =>
2334
{
24-
var token = await authority.AcquireToken(targetUri, credentials, resultType, tokenScope);
35+
Task.Run(async () =>
36+
{
37+
Interlocked.Increment(ref count);
2538

26-
Assert.NotNull(token);
39+
AuthenticationResult token = await authority.AcquireToken(targetUri, credentials, resultType, tokenScope);
2740

41+
Assert.NotNull(token);
42+
}).Wait();
2843
});
44+
45+
Assert.Equal(values.Count, count);
2946
}
3047
}
3148
}

Bitbucket.Authentication/Test/Bitbucket.Authentication.Test.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
<Compile Include="Properties\AssemblyInfo.cs" />
5656
</ItemGroup>
5757
<ItemGroup>
58+
<ProjectReference Include="..\..\Microsoft.Alm.Authentication\Proxy\Microsoft.Alm.Authentication.Proxy.csproj">
59+
<Project>{04151231-fe04-4a05-943a-54eb952cea62}</Project>
60+
<Name>Microsoft.Alm.Authentication.Proxy</Name>
61+
</ProjectReference>
62+
<ProjectReference Include="..\..\Microsoft.Alm.Authentication\Test\Microsoft.Alm.Authentication.Test.csproj">
63+
<Project>{19781214-371F-415C-93C5-44CEAA0E9A34}</Project>
64+
<Name>Microsoft.Alm.Authentication.Test</Name>
65+
</ProjectReference>
5866
<ProjectReference Include="..\Proxy\Bitbucket.Authentication.Proxy.csproj">
5967
<Project>{04151231-2501-4212-a7f7-c07e932b4a4c}</Project>
6068
<Name>Bitbucket.Authentication.Proxy</Name>
@@ -88,4 +96,4 @@
8896
<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.2.8.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.2.8.0\build\Microsoft.Net.Compilers.props'))" />
8997
</Target>
9098
<Import Project="..\..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
91-
</Project>
99+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/**** Git Process Management Library ****
2+
*
3+
* Copyright (c) Microsoft Corporation
4+
* All rights reserved.
5+
*
6+
* MIT License
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights to
11+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12+
* the Software, and to permit persons to whom the Software is furnished to do so,
13+
* subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22+
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
**/
25+
26+
// Use `Formatting.Indented` to ease review readability.
27+
{
28+
"ExtendedData": [],
29+
"DisplayName": "AuthorityTest_VerifyAcquireTokenAcceptsValidAuthenticationResultTypes",
30+
"ResultPath": "C:\\Src\\Microsoft.Alm\\Gcm\\Bitbucket.Authentication\\Test\\Results",
31+
"Services": {
32+
"Network": {
33+
"Operations": [
34+
{
35+
"Methods": [
36+
{
37+
"Method": "HttpGetAsync",
38+
"Queries": [
39+
{
40+
"Ordinal": 1,
41+
"Request": {
42+
"Headers": [
43+
"accept=*/*",
44+
"accept-encoding=gzip",
45+
"accept-encoding=deflate",
46+
"User-Agent=Microsoft.Alm.Authentication",
47+
"User-Agent=(Microsoft Windows NT 10.0.17134.0; Win32NT; x64)",
48+
"User-Agent=CLR/4.0.30319",
49+
"User-Agent=git-tools/4.6.0"
50+
],
51+
"Flags": 27
52+
},
53+
"Response": {
54+
"Content": {
55+
"AsString": "",
56+
"ContentType": "text/html",
57+
"HasContent": true
58+
},
59+
"Headers": [
60+
"WWW-Authenticate=Basic realm=\"Bitbucket.org HTTP\""
61+
],
62+
"StatusCode": 401
63+
}
64+
},
65+
{
66+
"Ordinal": 2,
67+
"Request": {
68+
"Headers": [
69+
"accept=*/*",
70+
"accept-encoding=gzip",
71+
"accept-encoding=deflate",
72+
"User-Agent=Microsoft.Alm.Authentication",
73+
"User-Agent=(Microsoft Windows NT 10.0.17134.0; Win32NT; x64)",
74+
"User-Agent=CLR/4.0.30319",
75+
"User-Agent=git-tools/4.6.0"
76+
],
77+
"Flags": 27
78+
},
79+
"Response": {
80+
"Content": {
81+
"AsString": "",
82+
"ContentType": "text/html",
83+
"HasContent": true
84+
},
85+
"Headers": [
86+
"WWW-Authenticate=Basic realm=\"Bitbucket.org HTTP\""
87+
],
88+
"StatusCode": 401
89+
}
90+
},
91+
{
92+
"Ordinal": 3,
93+
"Request": {
94+
"Headers": [
95+
"accept=*/*",
96+
"accept-encoding=gzip",
97+
"accept-encoding=deflate",
98+
"User-Agent=Microsoft.Alm.Authentication",
99+
"User-Agent=(Microsoft Windows NT 10.0.17134.0; Win32NT; x64)",
100+
"User-Agent=CLR/4.0.30319",
101+
"User-Agent=git-tools/4.6.0"
102+
],
103+
"Flags": 27
104+
},
105+
"Response": {
106+
"Content": {
107+
"AsString": "",
108+
"ContentType": "text/html",
109+
"HasContent": true
110+
},
111+
"Headers": [
112+
"WWW-Authenticate=Basic realm=\"Bitbucket.org HTTP\""
113+
],
114+
"StatusCode": 401
115+
}
116+
}
117+
]
118+
}
119+
],
120+
"QueryUrl": "https://api.bitbucket.org/2.0/user"
121+
}
122+
]
123+
},
124+
"Settings": {
125+
"EnvironmentVariables": [
126+
{
127+
"Target": 0,
128+
"Values": [
129+
{
130+
"Name": "HOME",
131+
"Variable": "C:\\Users\\Tester"
132+
},
133+
{
134+
"Name": "GCM_DEBUG"
135+
}
136+
]
137+
}
138+
],
139+
"ExitCode": 0,
140+
"ExpandVariables": [],
141+
"Is64BitOperatingSystem": false,
142+
"OsVersion": 0,
143+
"SpecialFolders": []
144+
},
145+
"Storage": {
146+
"Operations": []
147+
},
148+
"Gui": {
149+
"Operations": []
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)