Skip to content

Commit aa1b192

Browse files
Merge pull request #119 from SixLabors/js/prove-asynlock-works
Add Parallel Identical Query Tests.
2 parents 72c2cb6 + 12c566d commit aa1b192

File tree

5 files changed

+85
-16
lines changed

5 files changed

+85
-16
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ jobs:
1515
strategy:
1616
matrix:
1717
options:
18+
- os: macos-latest
19+
framework: netcoreapp3.1
20+
runtime: -x64
21+
codecov: false
1822
- os: ubuntu-latest
1923
framework: netcoreapp3.1
2024
runtime: -x64
@@ -45,22 +49,19 @@ jobs:
4549
git fetch --prune --unshallow
4650
git submodule -q update --init --recursive
4751
48-
- name: Install Azurite Linux
49-
if: matrix.options.os == 'ubuntu-latest'
52+
- name: Setup Azurite
53+
if: matrix.options.os != 'windows-latest'
5054
shell: bash
51-
run: sudo npm install -g azurite
52-
53-
- name: Use Azurite Linux
54-
if: matrix.options.os == 'ubuntu-latest'
55-
shell: bash
56-
run: sudo azurite --loose &
55+
run: |
56+
sudo npm install -g azurite
57+
sudo azurite --loose &
5758
58-
- name: Use Azure Storage Emulator Windows
59+
- name: Setup Azurite Windows
5960
if: matrix.options.os == 'windows-latest'
60-
shell: cmd
61+
shell: bash
6162
run: |
62-
"%ProgramFiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init /server "(localdb)\MsSqlLocalDb"
63-
"%ProgramFiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
63+
npm install -g azurite
64+
azurite --loose &
6465
6566
- name: Build
6667
shell: pwsh

samples/ImageSharp.Web.Sample/wwwroot/index.html

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<meta charset="utf-8" />
@@ -171,6 +171,35 @@ <h2>Background Color</h2>
171171
</p>
172172
</div>
173173
</section>
174+
<hr />
175+
<section>
176+
<h2>Identical Queries</h2>
177+
<p>Demonstrates that the middleware handles identical queries without file contention.</p>
178+
<div>
179+
<p>
180+
<code>imagesharp-logo.png?width=123</code>
181+
</p>
182+
<p>
183+
<img src="imagesharp-logo.png?width=123" />
184+
</p>
185+
</div>
186+
<div>
187+
<p>
188+
<code>imagesharp-logo.png?width=123</code>
189+
</p>
190+
<p>
191+
<img src="imagesharp-logo.png?width=123" />
192+
</p>
193+
</div>
194+
<div>
195+
<p>
196+
<code>imagesharp-logo.png?width=123</code>
197+
</p>
198+
<p>
199+
<img src="imagesharp-logo.png?width=123" />
200+
</p>
201+
</div>
202+
</section>
174203
</main>
175204
</body>
176-
</html>
205+
</html>

src/ImageSharp.Web/FormatUtilities.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Runtime.CompilerServices;
78
using Microsoft.AspNetCore.WebUtilities;
89
using Microsoft.Extensions.Options;
910
using Microsoft.Extensions.Primitives;
@@ -46,6 +47,7 @@ public FormatUtilities(IOptions<ImageSharpMiddlewareOptions> options)
4647
/// </summary>
4748
/// <param name="uri">The full request uri.</param>
4849
/// <returns>The <see cref="string"/>.</returns>
50+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4951
public string GetExtensionFromUri(string uri)
5052
{
5153
// TODO: Investigate using span to reduce allocations here.
@@ -81,6 +83,7 @@ public string GetExtensionFromUri(string uri)
8183
/// </summary>
8284
/// <param name="contentType">The content type (mime-type).</param>
8385
/// <returns>The <see cref="string"/>.</returns>
86+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8487
public string GetExtensionFromContentType(string contentType) => this.fileExtension[contentType];
8588
}
8689
}

tests/ImageSharp.Web.Tests/Processing/AzureBlobStorageCacheServerTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Linq;
67
using System.Net;
78
using System.Net.Http;
89
using System.Threading.Tasks;
@@ -16,6 +17,7 @@ public class AzureBlobStorageCacheServerTests : ServerTestBase<AzureBlobStorageC
1617
{
1718
private const int Width = 20;
1819
private static readonly string Command = "?width=" + Width + "&v=" + Guid.NewGuid().ToString();
20+
private static readonly string Command2 = "?width=" + (Width + 1) + "&v=" + Guid.NewGuid().ToString();
1921

2022
public AzureBlobStorageCacheServerTests(AzureBlobStorageCacheTestServerFixture fixture)
2123
: base(fixture)
@@ -25,7 +27,7 @@ public AzureBlobStorageCacheServerTests(AzureBlobStorageCacheTestServerFixture f
2527
[Theory]
2628
[InlineData(TestConstants.PhysicalTestImage)]
2729
[InlineData(TestConstants.AzureTestImage)]
28-
public async Task CanProcessAndResolveImage(string url)
30+
public async Task CanProcessAndResolveImageAsync(string url)
2931
{
3032
string ext = Path.GetExtension(url);
3133
IImageFormat format = Configuration.Default.ImageFormatsManager.FindFormatByFileExtension(ext);
@@ -97,5 +99,21 @@ public async Task CanProcessAndResolveImage(string url)
9799
request.Dispose();
98100
response.Dispose();
99101
}
102+
103+
[Theory]
104+
[InlineData(TestConstants.PhysicalTestImage)]
105+
[InlineData(TestConstants.AzureTestImage)]
106+
public async Task CanProcessMultipleIdenticalQueriesAsync(string url)
107+
{
108+
Task[] tasks = Enumerable.Range(0, 5).Select(_ => Task.Run(async () =>
109+
{
110+
using HttpResponseMessage response = await this.HttpClient.GetAsync(url + Command2);
111+
Assert.NotNull(response);
112+
})).ToArray();
113+
114+
var all = Task.WhenAll(tasks);
115+
await all;
116+
Assert.True(all.IsCompletedSuccessfully);
117+
}
100118
}
101119
}

tests/ImageSharp.Web.Tests/Processing/PhysicalFileSystemCacheServerTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.IO;
6+
using System.Linq;
67
using System.Net;
78
using System.Net.Http;
89
using System.Threading.Tasks;
@@ -16,6 +17,7 @@ public class PhysicalFileSystemCacheServerTests : ServerTestBase<PhysicalFileSys
1617
{
1718
private const int Width = 20;
1819
private static readonly string Command = "?width=" + Width + "&v=" + Guid.NewGuid().ToString();
20+
private static readonly string Command2 = "?width=" + (Width + 1) + "&v=" + Guid.NewGuid().ToString();
1921

2022
public PhysicalFileSystemCacheServerTests(PhysicalFileSystemCacheTestServerFixture fixture)
2123
: base(fixture)
@@ -25,7 +27,7 @@ public PhysicalFileSystemCacheServerTests(PhysicalFileSystemCacheTestServerFixtu
2527
[Theory]
2628
[InlineData(TestConstants.PhysicalTestImage)]
2729
[InlineData(TestConstants.AzureTestImage)]
28-
public async Task CanProcessAndResolveImage(string url)
30+
public async Task CanProcessAndResolveImageAsync(string url)
2931
{
3032
string ext = Path.GetExtension(url);
3133
IImageFormat format = Configuration.Default.ImageFormatsManager.FindFormatByFileExtension(ext);
@@ -97,5 +99,21 @@ public async Task CanProcessAndResolveImage(string url)
9799
request.Dispose();
98100
response.Dispose();
99101
}
102+
103+
[Theory]
104+
[InlineData(TestConstants.PhysicalTestImage)]
105+
[InlineData(TestConstants.AzureTestImage)]
106+
public async Task CanProcessMultipleIdenticalQueriesAsync(string url)
107+
{
108+
Task[] tasks = Enumerable.Range(0, 5).Select(_ => Task.Run(async () =>
109+
{
110+
using HttpResponseMessage response = await this.HttpClient.GetAsync(url + Command2);
111+
Assert.NotNull(response);
112+
})).ToArray();
113+
114+
var all = Task.WhenAll(tasks);
115+
await all;
116+
Assert.True(all.IsCompletedSuccessfully);
117+
}
100118
}
101119
}

0 commit comments

Comments
 (0)