Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Commit

Permalink
Revert "Added timeouts to tests"
Browse files Browse the repository at this point in the history
This reverts commit 766aa38.
  • Loading branch information
fubar-coder committed May 13, 2016
1 parent f99d121 commit c832923
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 47 deletions.
20 changes: 7 additions & 13 deletions RestSharp.Portable.Test/AuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using Org.BouncyCastle.Crypto.Parameters;
Expand Down Expand Up @@ -34,15 +33,14 @@ public async Task TestHttpBasicAuth(Type factoryType)
{
CookieContainer = new CookieContainer(),
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
Credentials = new NetworkCredential(username, password),
Authenticator = new HttpBasicAuthenticator(),
})
{
var request = new RestRequest("basic-auth/{username}/{password}", Method.GET);
request.AddUrlSegment("username", username);
request.AddUrlSegment("password", password);
var response = await client.Execute<AuthenticationResult>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<AuthenticationResult>(request);

Assert.True(response.Data.Authenticated);
Assert.Equal(username, response.Data.User);
Expand All @@ -61,15 +59,14 @@ public async Task TestHttpBasicAuthHidden(Type factoryType)
{
CookieContainer = new CookieContainer(),
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
Credentials = new NetworkCredential(username, password),
Authenticator = new HttpHiddenBasicAuthenticator(),
})
{
var request = new RestRequest("hidden-basic-auth/{username}/{password}", Method.GET);
request.AddUrlSegment("username", username);
request.AddUrlSegment("password", password);
var response = await client.Execute<AuthenticationResult>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<AuthenticationResult>(request);

Assert.True(response.Data.Authenticated);
Assert.Equal(username, response.Data.User);
Expand All @@ -88,15 +85,14 @@ public async Task TestHttpDigestAuth(Type factoryType)
{
CookieContainer = new CookieContainer(),
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
Credentials = new NetworkCredential(username, password),
Authenticator = new HttpDigestAuthenticator()
})
{
var request = new RestRequest("digest-auth/auth/{username}/{password}", Method.GET);
request.AddUrlSegment("username", username);
request.AddUrlSegment("password", password);
var response = await client.Execute<AuthenticationResult>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<AuthenticationResult>(request);

Assert.True(response.Data.Authenticated);
Assert.Equal(username, response.Data.User);
Expand All @@ -115,7 +111,6 @@ public async Task TestHttpDigestAuthInt(Type factoryType)
{
CookieContainer = new CookieContainer(),
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
Credentials = new NetworkCredential(username, password),
Authenticator = new HttpDigestAuthenticator()
})
Expand All @@ -125,7 +120,7 @@ public async Task TestHttpDigestAuthInt(Type factoryType)
request.AddUrlSegment("username", username);
request.AddUrlSegment("password", password);
////request.AddParameter("param1", "val1");
var response = await client.Execute<AuthenticationResult>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<AuthenticationResult>(request);

Assert.True(response.Data.Authenticated);
Assert.Equal(username, response.Data.User);
Expand Down Expand Up @@ -178,7 +173,6 @@ private async Task TestOAuth10(IHttpClientFactory httpClientFactory, ISignatureP
using (var client = new RestClient("http://oauthbin.com/v1/")
{
HttpClientFactory = httpClientFactory,
Timeout = TimeSpan.FromSeconds(10)
})
{
var consumerKey = "key";
Expand All @@ -192,7 +186,7 @@ private async Task TestOAuth10(IHttpClientFactory httpClientFactory, ISignatureP

{
var request = new RestRequest("request-token");
var response = await client.Execute(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute(request);
var requestTokenResponse = Encoding.UTF8.GetString(response.RawBytes);
Assert.DoesNotContain('\n', requestTokenResponse);

Expand Down Expand Up @@ -221,7 +215,7 @@ private async Task TestOAuth10(IHttpClientFactory httpClientFactory, ISignatureP

{
var request = new RestRequest("access-token");
var response = await client.Execute(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute(request);
var accessTokenResponse = Encoding.UTF8.GetString(response.RawBytes);
Assert.DoesNotContain('\n', accessTokenResponse);

Expand Down Expand Up @@ -250,7 +244,7 @@ private async Task TestOAuth10(IHttpClientFactory httpClientFactory, ISignatureP
var request = new RestRequest("echo", Method.POST);
request.AddParameter("one", "1");
request.AddParameter("two", "2");
var response = await client.Execute(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute(request);
var text = Encoding.UTF8.GetString(response.RawBytes);
Assert.DoesNotContain('\n', text);

Expand Down
30 changes: 10 additions & 20 deletions RestSharp.Portable.Test/IssueTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

using RestSharp.Portable.Authenticators;
Expand All @@ -23,15 +22,14 @@ public async Task TestIssue12_Post1(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
var tmp = new string('a', 70000);

var request = new RestRequest("post", Method.POST);
request.AddParameter("param1", tmp);

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Form);
Assert.True(response.Data.Form.ContainsKey("param1"));
Expand All @@ -48,7 +46,6 @@ public async Task TestIssue12_Post2(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
var tmp = new string('a', 70000);
Expand All @@ -57,7 +54,7 @@ public async Task TestIssue12_Post2(Type factoryType)
request.AddParameter("param1", tmp);
request.AddParameter("param2", "param2");

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Form);
Assert.True(response.Data.Form.ContainsKey("param1"));
Expand All @@ -77,7 +74,6 @@ public void TestIssue16(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
var request = new RestRequest("get?a={a}");
Expand All @@ -97,16 +93,15 @@ public void TestIssue19(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
var req1 = new RestRequest("post", Method.POST);
req1.AddParameter("a", "value-of-a");
var t1 = client.Execute<HttpBinResponse>(req1, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var t1 = client.Execute<HttpBinResponse>(req1);

var req2 = new RestRequest("post", Method.POST);
req2.AddParameter("ab", "value-of-ab");
var t2 = client.Execute<HttpBinResponse>(req2, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var t2 = client.Execute<HttpBinResponse>(req2);

Task.WaitAll(t1, t2);

Expand All @@ -130,14 +125,13 @@ public async Task TestIssue23(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
client.Authenticator = new HttpBasicAuthenticator();
client.Credentials = new NetworkCredential("foo", "bar");
var request = new RestRequest("post", Method.GET);
request.AddJsonBody("foo");
await client.Execute(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
await client.Execute(request);
}
}

Expand All @@ -151,7 +145,6 @@ public void TestIssue25(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
var req1 = new RestRequest("post", Method.POST);
Expand All @@ -160,8 +153,8 @@ public void TestIssue25(Type factoryType)
var req2 = new RestRequest("post", Method.POST);
req2.AddParameter("ab", "value-of-ab");

var t1 = client.Execute<HttpBinResponse>(req1, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var t2 = client.Execute<HttpBinResponse>(req2, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var t1 = client.Execute<HttpBinResponse>(req1);
var t2 = client.Execute<HttpBinResponse>(req2);
Task.WaitAll(t1, t2);

Assert.NotNull(t1.Result.Data);
Expand All @@ -184,13 +177,12 @@ public async Task TestIssue29_CollectionModeMultiPart(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
var req = new RestRequest("post", Method.POST);
req.AddParameter("a", "value-of-a");
req.ContentCollectionMode = ContentCollectionMode.MultiPart;
var resp = await client.Execute<HttpBinResponse>(req, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var resp = await client.Execute<HttpBinResponse>(req);
Assert.NotNull(resp.Data);
Assert.NotNull(resp.Data.Form);
Assert.True(resp.Data.Form.ContainsKey("a"));
Expand All @@ -206,13 +198,12 @@ public async Task TestIssue29_ContentTypeParameter(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10)
})
{
var req = new RestRequest("post", Method.POST);
req.AddParameter("a", "value-of-a");
req.AddHeader("content-type", "application/x-www-form-urlencoded;charset=utf-8");
var resp = await client.Execute<HttpBinResponse>(req, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var resp = await client.Execute<HttpBinResponse>(req);
Assert.NotNull(resp.Data);
Assert.NotNull(resp.Data.Form);
Assert.True(resp.Data.Form.ContainsKey("a"));
Expand All @@ -228,12 +219,11 @@ public async Task TestIssue53(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
IgnoreResponseStatusCode = true,
})
{
var req = new RestRequest("get", Method.GET);
var resp = await client.Execute<HttpBinResponse>(req, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var resp = await client.Execute<HttpBinResponse>(req);
Assert.Null(resp.Data);
}
}
Expand Down
13 changes: 4 additions & 9 deletions RestSharp.Portable.Test/OtherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using RestSharp.Portable.HttpClient;
Expand All @@ -24,14 +23,13 @@ public async Task TestMultipleRequests(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
})
{
{
var request = new RestRequest("post", Method.POST);
request.AddParameter("param1", "param1");

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Form);
Assert.True(response.Data.Form.ContainsKey("param1"));
Expand All @@ -42,7 +40,7 @@ public async Task TestMultipleRequests(Type factoryType)
var request = new RestRequest("post", Method.POST);
request.AddParameter("param1", "param1+");

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Form);
Assert.True(response.Data.Form.ContainsKey("param1"));
Expand All @@ -59,14 +57,13 @@ public async Task TestPutRequestByteArray(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
})
{
var request = new RestRequest("put", Method.PUT);
var data = Encoding.UTF8.GetBytes("Hello!");
request.AddParameter(string.Empty, data, ParameterType.RequestBody);

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.NotNull(response.Data);
Assert.Equal("Hello!", response.Data.Data);
}
Expand All @@ -80,7 +77,6 @@ public async Task TestPutRequestJson(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
})
{
var request = new RestRequest("put", Method.PUT);
Expand All @@ -90,7 +86,7 @@ public async Task TestPutRequestJson(Type factoryType)
hello = "world",
});

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.NotNull(response.Data);
Assert.NotNull(response.Data.Args);
Assert.Contains("hello", response.Data.Args.Keys);
Expand All @@ -109,7 +105,6 @@ public void TestUserAgent(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
})
{
Assert.NotNull(client.UserAgent);
Expand Down
7 changes: 2 additions & 5 deletions RestSharp.Portable.Test/PostHeaderRequestTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using RestSharp.Portable.HttpClient;
Expand All @@ -21,14 +20,13 @@ public async Task TestRequestParameter(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
})
{
var request = new RestRequest("post", Method.POST);
request.AddHeader("Restsharp-Test1", "TestValue1");
request.AddParameter("param1", "ParamValue1");

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.Equal("ParamValue1", response.Data.Form["param1"]);
Assert.Equal("TestValue1", response.Data.Headers["Restsharp-Test1"]);
}
Expand All @@ -42,15 +40,14 @@ public async Task TestDefaultParameter(Type factoryType)
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
Timeout = TimeSpan.FromSeconds(10),
})
{
client.AddDefaultParameter("Restsharp-Test2", "TestValue2", ParameterType.HttpHeader);

var request = new RestRequest("post", Method.POST);
request.AddParameter("param1", "ParamValue1");

var response = await client.Execute<HttpBinResponse>(request, new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token);
var response = await client.Execute<HttpBinResponse>(request);
Assert.Equal("ParamValue1", response.Data.Form["param1"]);
Assert.Equal("TestValue2", response.Data.Headers["Restsharp-Test2"]);
}
Expand Down

0 comments on commit c832923

Please sign in to comment.