[SignalR] Fix DataProtection with parallel tests (#21271)

This commit is contained in:
Brennan 2020-04-28 14:53:27 -07:00 committed by GitHub
parent 5fc067266f
commit 600d5ff497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -3,10 +3,12 @@
using System;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.Routing;
@ -49,6 +51,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
IssuerSigningKey = SecurityKey
};
});
// Since tests run in parallel, it's possible multiple servers will startup and read files being written by another test
// Use a unique directory per server to avoid this collision
services.AddDataProtection()
.PersistKeysToFileSystem(Directory.CreateDirectory(Path.GetRandomFileName()));
}
public void Configure(IApplicationBuilder app)

View File

@ -3,11 +3,13 @@
using System;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
@ -63,6 +65,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
services.AddAuthorization();
services.AddSingleton<IAuthorizationHandler, TestAuthHandler>();
// Since tests run in parallel, it's possible multiple servers will startup and read files being written by another test
// Use a unique directory per server to avoid this collision
services.AddDataProtection()
.PersistKeysToFileSystem(Directory.CreateDirectory(Path.GetRandomFileName()));
}
public void Configure(IApplicationBuilder app)