Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions BrowserCache/SessionStorageCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void RunTest(WebDriver driver, bool enableCookies)
ClientServerUrl,
_app.BaseUrl.ToString(),
BuildPage(enableCookies),
ExampleApps.JsonEndpointPath,
ExampleApps.JsonEndpointPaths,
clientServerTokenSource.Token);
clientServer = serverListener.Listener;
clientHttpServer = serverListener.Server;
Expand Down Expand Up @@ -265,9 +265,12 @@ private static void AssertSameResults(

private int CountJsonPosts()
{
var expected = $"POST {ExampleApps.JsonEndpointPath}";
var expected = ExampleApps.JsonEndpointPaths
.Select(p => $"POST {p}")
.ToList();
return clientHttpServer.RequestLog
.Count(r => string.Equals(r, expected, StringComparison.OrdinalIgnoreCase));
.Count(r => expected.Any(e => string.Equals(
r, e, StringComparison.OrdinalIgnoreCase)));
}

private static List<string> GetSessionStorageKeys(IJavaScriptExecutor js)
Expand Down
21 changes: 20 additions & 1 deletion Examples/ExampleApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ public static class ExampleApps
? descriptor.JsonEndpointPath
: "/51dpipeline/json";

/// <summary>
/// Every path the selected language's client-side script may post to,
/// being <see cref="JsonEndpointPath"/> and any older path the
/// language still answers.
/// </summary>
public static IReadOnlyList<string> JsonEndpointPaths
{
get
{
var paths = new List<string> { JsonEndpointPath };
if (Descriptors.TryGetValue(SelectedLang, out var descriptor)
&& descriptor.AlternativeJsonEndpointPaths != null)
{
paths.AddRange(descriptor.AlternativeJsonEndpointPaths);
}
return paths;
}
}

/// <summary>
/// Element the selected language's page renders its client-side results
/// into. Read from the descriptor so it is available for the CI case
Expand Down Expand Up @@ -245,7 +264,7 @@ public static ExampleAppOptions BuildOptions(
BuildArgs: new[] { "-pl", "web/getting-started.cloud", "-am", "package", "-DskipTests" },
RunArtifactGlob: "web/getting-started.cloud/target/*-jar-with-dependencies.jar",
BuildTimeoutSeconds: 600,
JsonEndpointPath: "/51Degrees.core.json",
AlternativeJsonEndpointPaths: new[] { "/51Degrees.core.json" },
// the java page renders the client-side results into its
// Apple detection section rather than the shared container
ClientResultsElementId: "apple-detection"),
Expand Down
10 changes: 8 additions & 2 deletions Examples/ExampleDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ namespace FiftyOne.Pipeline.Cloud.SeleniumTests.Examples
/// integration picks its own, so a test that proxies or counts those
/// requests has to ask the descriptor rather than assume one: dotnet and
/// rust use the default, java uses /51Degrees.core.json, and node, python
/// and php use /json.
/// and php use /json, and java uses the default and still answers the
/// older /51Degrees.core.json.
/// </param>
/// <param name="AlternativeJsonEndpointPaths">
/// Older paths the integration still answers, so a test accepts a build
/// whose script uses either.
/// </param>
/// <param name="ClientResultsElementId">
/// Id of the element the example's page asks the shared examples helper to
Expand All @@ -44,5 +49,6 @@ public sealed record ExampleDescriptor(
string RunArtifactGlob = null,
int BuildTimeoutSeconds = 0,
string JsonEndpointPath = "/51dpipeline/json",
string ClientResultsElementId = "content");
string ClientResultsElementId = "content",
IReadOnlyList<string> AlternativeJsonEndpointPaths = null);
}
22 changes: 13 additions & 9 deletions TestsCommon/Helpers/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,32 @@ public static ServerListener ReverseProxyListener(
/// Creates an HttpListener that serves <paramref name="pageData"/>
/// for page paths and proxies the 51Degrees script and pipeline
/// endpoints to <paramref name="exampleUrl"/> without caching.
/// <paramref name="jsonEndpointPath"/> is the path the client-side
/// script posts refreshed evidence to, which differs per web
/// integration, so the caller supplies the one its example uses.
/// <paramref name="jsonEndpointPaths"/> are the paths the client-side
/// script may post refreshed evidence to, which differ per web
/// integration, so the caller supplies the ones its example uses.
/// </summary>
public static ServerListener ExampleProxyListener(
string clientUrl,
string exampleUrl,
string pageData,
string jsonEndpointPath,
IEnumerable<string> jsonEndpointPaths,
CancellationToken token)
{
var listener = new HttpListener();
listener.Prefixes.Add(clientUrl);
listener.Start();

var routes = new Dictionary<string, string>
{
["/51Degrees.core.js"] = exampleUrl,
};
foreach (var path in jsonEndpointPaths)
{
routes[path] = exampleUrl;
}
var server = new HttpServer(listener, pageData)
{
ProxyRoutes = new Dictionary<string, string>
{
["/51Degrees.core.js"] = exampleUrl,
[jsonEndpointPath] = exampleUrl,
},
ProxyRoutes = routes,
ProxiedHeaderOverrides = new Dictionary<string, string>
{
["Cache-Control"] = "no-store",
Expand Down
Loading