Skip to content

Commit add7973

Browse files
Fix up processing tests
1 parent 6687cdd commit add7973

11 files changed

Lines changed: 235 additions & 586 deletions

.github/workflows/build-and-test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ jobs:
144144
run: ./ci-test.ps1 "${{matrix.options.os}}" "${{matrix.options.framework}}" "${{matrix.options.runtime}}" "${{matrix.options.codecov}}"
145145
env:
146146
SIXLABORS_TESTING: True
147-
CI: True # This should be true but doesn't seem to be.
148147
XUNIT_PATH: .\tests\ImageSharp.Web.Tests # Required for xunit
149148

150149
- name: Codecov Update
Lines changed: 3 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,16 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using System;
5-
using System.IO;
6-
using System.Linq;
7-
using System.Net;
8-
using System.Net.Http;
9-
using System.Threading.Tasks;
10-
using SixLabors.ImageSharp.Formats;
114
using SixLabors.ImageSharp.Web.Tests.TestUtilities;
12-
using Xunit;
5+
using Xunit.Abstractions;
136

147
namespace SixLabors.ImageSharp.Web.Tests.Processing
158
{
169
public class AWSS3StorageCacheServerTests : ServerTestBase<AWSS3StorageCacheTestServerFixture>
1710
{
18-
private const int Width = 20;
19-
private static readonly string Command = "?width=" + Width + "&v=" + Guid.NewGuid().ToString();
20-
private static readonly string Command2 = "?width=" + (Width + 1) + "&v=" + Guid.NewGuid().ToString();
21-
22-
public AWSS3StorageCacheServerTests(AWSS3StorageCacheTestServerFixture fixture)
23-
: base(fixture)
24-
{
25-
}
26-
27-
[Theory]
28-
[InlineData(TestConstants.PhysicalTestImage)]
29-
[InlineData(TestConstants.AzureTestImage)]
30-
[InlineData(TestConstants.AWSTestImage)]
31-
public async Task CanProcessAndResolveImageAsync(string url)
11+
public AWSS3StorageCacheServerTests(AWSS3StorageCacheTestServerFixture fixture, ITestOutputHelper outputHelper)
12+
: base(fixture, outputHelper, TestConstants.AWSTestImage)
3213
{
33-
string ext = Path.GetExtension(url);
34-
IImageFormat format = Configuration.Default.ImageFormatsManager.FindFormatByFileExtension(ext);
35-
36-
// First response
37-
HttpResponseMessage response = await this.HttpClient.GetAsync(url + Command);
38-
39-
Assert.NotNull(response);
40-
Assert.True(response.IsSuccessStatusCode);
41-
Assert.True(response.Content.Headers.ContentLength > 0);
42-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
43-
44-
(Image Image, IImageFormat Format) actual = await Image.LoadWithFormatAsync(await response.Content.ReadAsStreamAsync());
45-
using Image image = actual.Image;
46-
47-
Assert.Equal(Width, image.Width);
48-
Assert.Equal(format, actual.Format);
49-
50-
response.Dispose();
51-
52-
// Cached Response
53-
response = await this.HttpClient.GetAsync(url + Command);
54-
55-
Assert.NotNull(response);
56-
Assert.True(response.IsSuccessStatusCode);
57-
Assert.True(response.Content.Headers.ContentLength > 0);
58-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
59-
60-
(Image Image, IImageFormat Format) cachedActual = await Image.LoadWithFormatAsync(await response.Content.ReadAsStreamAsync());
61-
using Image cached = cachedActual.Image;
62-
63-
Assert.Equal(Width, cached.Width);
64-
Assert.Equal(format, actual.Format);
65-
66-
response.Dispose();
67-
68-
// 304 response
69-
var request = new HttpRequestMessage
70-
{
71-
RequestUri = new Uri(url + Command),
72-
Method = HttpMethod.Get,
73-
};
74-
75-
request.Headers.IfModifiedSince = DateTimeOffset.UtcNow;
76-
77-
response = await this.HttpClient.SendAsync(request);
78-
79-
// This test is flaky in the CI environment.
80-
if (!TestEnvironment.RunsOnCI)
81-
{
82-
Assert.Equal(HttpStatusCode.NotModified, response.StatusCode);
83-
Assert.Equal(0, response.Content.Headers.ContentLength);
84-
}
85-
86-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
87-
88-
request.Dispose();
89-
response.Dispose();
90-
91-
// 412 response
92-
request = new HttpRequestMessage
93-
{
94-
RequestUri = new Uri(url + Command),
95-
Method = HttpMethod.Get,
96-
};
97-
98-
request.Headers.IfUnmodifiedSince = DateTimeOffset.MinValue;
99-
100-
response = await this.HttpClient.SendAsync(request);
101-
102-
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
103-
Assert.Equal(0, response.Content.Headers.ContentLength);
104-
105-
request.Dispose();
106-
response.Dispose();
107-
}
108-
109-
[Theory]
110-
[InlineData(TestConstants.PhysicalTestImage)]
111-
[InlineData(TestConstants.AzureTestImage)]
112-
[InlineData(TestConstants.AWSTestImage)]
113-
public async Task CanProcessMultipleIdenticalQueriesAsync(string url)
114-
{
115-
Task[] tasks = Enumerable.Range(0, 100).Select(i => Task.Run(async () =>
116-
{
117-
string command = i % 2 == 0 ? Command : Command2;
118-
using HttpResponseMessage response = await this.HttpClient.GetAsync(url + command);
119-
Assert.NotNull(response);
120-
Assert.True(response.IsSuccessStatusCode);
121-
Assert.True(response.Content.Headers.ContentLength > 0);
122-
})).ToArray();
123-
124-
var all = Task.WhenAll(tasks);
125-
await all;
126-
Assert.True(all.IsCompletedSuccessfully);
12714
}
12815
}
12916
}
Lines changed: 3 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,16 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using System;
5-
using System.IO;
6-
using System.Linq;
7-
using System.Net;
8-
using System.Net.Http;
9-
using System.Threading.Tasks;
10-
using SixLabors.ImageSharp.Formats;
114
using SixLabors.ImageSharp.Web.Tests.TestUtilities;
12-
using Xunit;
5+
using Xunit.Abstractions;
136

147
namespace SixLabors.ImageSharp.Web.Tests.Processing
158
{
169
public class AzureBlobStorageCacheServerTests : ServerTestBase<AzureBlobStorageCacheTestServerFixture>
1710
{
18-
private const int Width = 20;
19-
private static readonly string Command = "?width=" + Width + "&v=" + Guid.NewGuid().ToString();
20-
private static readonly string Command2 = "?width=" + (Width + 1) + "&v=" + Guid.NewGuid().ToString();
21-
22-
public AzureBlobStorageCacheServerTests(AzureBlobStorageCacheTestServerFixture fixture)
23-
: base(fixture)
24-
{
25-
}
26-
27-
[Theory]
28-
[InlineData(TestConstants.PhysicalTestImage)]
29-
[InlineData(TestConstants.AzureTestImage)]
30-
[InlineData(TestConstants.AWSTestImage)]
31-
public async Task CanProcessAndResolveImageAsync(string url)
32-
{
33-
string ext = Path.GetExtension(url);
34-
IImageFormat format = Configuration.Default.ImageFormatsManager.FindFormatByFileExtension(ext);
35-
36-
// First response
37-
HttpResponseMessage response = await this.HttpClient.GetAsync(url + Command);
38-
39-
Assert.NotNull(response);
40-
Assert.True(response.IsSuccessStatusCode);
41-
Assert.True(response.Content.Headers.ContentLength > 0);
42-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
43-
44-
(Image Image, IImageFormat Format) actual = await Image.LoadWithFormatAsync(await response.Content.ReadAsStreamAsync());
45-
using Image image = actual.Image;
46-
47-
Assert.Equal(Width, image.Width);
48-
Assert.Equal(format, actual.Format);
49-
50-
response.Dispose();
51-
52-
// Cached Response
53-
response = await this.HttpClient.GetAsync(url + Command);
54-
55-
Assert.NotNull(response);
56-
Assert.True(response.IsSuccessStatusCode);
57-
Assert.True(response.Content.Headers.ContentLength > 0);
58-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
59-
60-
(Image Image, IImageFormat Format) cachedActual = await Image.LoadWithFormatAsync(await response.Content.ReadAsStreamAsync());
61-
using Image cached = cachedActual.Image;
62-
63-
Assert.Equal(Width, cached.Width);
64-
Assert.Equal(format, actual.Format);
65-
66-
response.Dispose();
67-
68-
// 304 response
69-
var request = new HttpRequestMessage
70-
{
71-
RequestUri = new Uri(url + Command),
72-
Method = HttpMethod.Get,
73-
};
74-
75-
request.Headers.IfModifiedSince = DateTimeOffset.UtcNow;
76-
77-
response = await this.HttpClient.SendAsync(request);
78-
79-
Assert.Equal(HttpStatusCode.NotModified, response.StatusCode);
80-
Assert.Equal(0, response.Content.Headers.ContentLength);
81-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
82-
83-
request.Dispose();
84-
response.Dispose();
85-
86-
// 412 response
87-
request = new HttpRequestMessage
88-
{
89-
RequestUri = new Uri(url + Command),
90-
Method = HttpMethod.Get,
91-
};
92-
93-
request.Headers.IfUnmodifiedSince = DateTimeOffset.MinValue;
94-
95-
response = await this.HttpClient.SendAsync(request);
96-
97-
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
98-
Assert.Equal(0, response.Content.Headers.ContentLength);
99-
100-
request.Dispose();
101-
response.Dispose();
102-
}
103-
104-
[Theory]
105-
[InlineData(TestConstants.PhysicalTestImage)]
106-
[InlineData(TestConstants.AzureTestImage)]
107-
[InlineData(TestConstants.AWSTestImage)]
108-
public async Task CanProcessMultipleIdenticalQueriesAsync(string url)
11+
public AzureBlobStorageCacheServerTests(AzureBlobStorageCacheTestServerFixture fixture, ITestOutputHelper outputHelper)
12+
: base(fixture, outputHelper, TestConstants.AzureTestImage)
10913
{
110-
Task[] tasks = Enumerable.Range(0, 100).Select(i => Task.Run(async () =>
111-
{
112-
string command = i % 2 == 0 ? Command : Command2;
113-
using HttpResponseMessage response = await this.HttpClient.GetAsync(url + command);
114-
Assert.NotNull(response);
115-
Assert.True(response.IsSuccessStatusCode);
116-
Assert.True(response.Content.Headers.ContentLength > 0);
117-
})).ToArray();
118-
119-
var all = Task.WhenAll(tasks);
120-
await all;
121-
Assert.True(all.IsCompletedSuccessfully);
12214
}
12315
}
12416
}
Lines changed: 3 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,16 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using System;
5-
using System.IO;
6-
using System.Linq;
7-
using System.Net;
8-
using System.Net.Http;
9-
using System.Threading.Tasks;
10-
using SixLabors.ImageSharp.Formats;
114
using SixLabors.ImageSharp.Web.Tests.TestUtilities;
12-
using Xunit;
5+
using Xunit.Abstractions;
136

147
namespace SixLabors.ImageSharp.Web.Tests.Processing
158
{
169
public class PhysicalFileSystemCacheServerTests : ServerTestBase<PhysicalFileSystemCacheTestServerFixture>
1710
{
18-
private const int Width = 20;
19-
private static readonly string Command = "?invalidcommand=qwerty&width=" + Width + "&v=" + Guid.NewGuid().ToString();
20-
private static readonly string Command2 = "?invalidcommand=qwerty&width=" + (Width + 1) + "&v=" + Guid.NewGuid().ToString();
21-
22-
public PhysicalFileSystemCacheServerTests(PhysicalFileSystemCacheTestServerFixture fixture)
23-
: base(fixture)
24-
{
25-
}
26-
27-
[Theory]
28-
[InlineData(TestConstants.PhysicalTestImage)]
29-
[InlineData(TestConstants.AzureTestImage)]
30-
[InlineData(TestConstants.AWSTestImage)]
31-
public async Task CanProcessAndResolveImageAsync(string url)
32-
{
33-
string ext = Path.GetExtension(url);
34-
IImageFormat format = Configuration.Default.ImageFormatsManager.FindFormatByFileExtension(ext);
35-
36-
// First response
37-
HttpResponseMessage response = await this.HttpClient.GetAsync(url + Command);
38-
39-
Assert.NotNull(response);
40-
Assert.True(response.IsSuccessStatusCode);
41-
Assert.True(response.Content.Headers.ContentLength > 0);
42-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
43-
44-
(Image Image, IImageFormat Format) actual = await Image.LoadWithFormatAsync(await response.Content.ReadAsStreamAsync());
45-
using Image image = actual.Image;
46-
47-
Assert.Equal(Width, image.Width);
48-
Assert.Equal(format, actual.Format);
49-
50-
response.Dispose();
51-
52-
// Cached Response
53-
response = await this.HttpClient.GetAsync(url + Command);
54-
55-
Assert.NotNull(response);
56-
Assert.True(response.IsSuccessStatusCode);
57-
Assert.True(response.Content.Headers.ContentLength > 0);
58-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
59-
60-
(Image Image, IImageFormat Format) cachedActual = await Image.LoadWithFormatAsync(await response.Content.ReadAsStreamAsync());
61-
using Image cached = cachedActual.Image;
62-
63-
Assert.Equal(Width, cached.Width);
64-
Assert.Equal(format, actual.Format);
65-
66-
response.Dispose();
67-
68-
// 304 response
69-
var request = new HttpRequestMessage
70-
{
71-
RequestUri = new Uri(url + Command),
72-
Method = HttpMethod.Get,
73-
};
74-
75-
request.Headers.IfModifiedSince = DateTimeOffset.UtcNow;
76-
77-
response = await this.HttpClient.SendAsync(request);
78-
79-
Assert.Equal(HttpStatusCode.NotModified, response.StatusCode);
80-
Assert.Equal(0, response.Content.Headers.ContentLength);
81-
Assert.Equal(format.DefaultMimeType, response.Content.Headers.ContentType.MediaType);
82-
83-
request.Dispose();
84-
response.Dispose();
85-
86-
// 412 response
87-
request = new HttpRequestMessage
88-
{
89-
RequestUri = new Uri(url + Command),
90-
Method = HttpMethod.Get,
91-
};
92-
93-
request.Headers.IfUnmodifiedSince = DateTimeOffset.MinValue;
94-
95-
response = await this.HttpClient.SendAsync(request);
96-
97-
Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode);
98-
Assert.Equal(0, response.Content.Headers.ContentLength);
99-
100-
request.Dispose();
101-
response.Dispose();
102-
}
103-
104-
[Theory]
105-
[InlineData(TestConstants.PhysicalTestImage)]
106-
[InlineData(TestConstants.AzureTestImage)]
107-
[InlineData(TestConstants.AWSTestImage)]
108-
public async Task CanProcessMultipleIdenticalQueriesAsync(string url)
11+
public PhysicalFileSystemCacheServerTests(PhysicalFileSystemCacheTestServerFixture fixture, ITestOutputHelper outputHelper)
12+
: base(fixture, outputHelper, TestConstants.PhysicalTestImage)
10913
{
110-
Task[] tasks = Enumerable.Range(0, 100).Select(i => Task.Run(async () =>
111-
{
112-
string command = i % 2 == 0 ? Command : Command2;
113-
using HttpResponseMessage response = await this.HttpClient.GetAsync(url + command);
114-
Assert.NotNull(response);
115-
Assert.True(response.IsSuccessStatusCode);
116-
Assert.True(response.Content.Headers.ContentLength > 0);
117-
})).ToArray();
118-
119-
var all = Task.WhenAll(tasks);
120-
await all;
121-
Assert.True(all.IsCompletedSuccessfully);
12214
}
12315
}
12416
}

0 commit comments

Comments
 (0)