Skip to content

Commit

Permalink
fix case where port number is lost using resumable (#343)
Browse files Browse the repository at this point in the history
* change how the resumable request urls are made to not lose the port number. Write tests for the URL formatting.

* increase timeout for test runs

- increase the timeout for long test runs
- also add concurrency rule to cancel outdated runs still in progress

---------

Co-authored-by: Chris Hirt <chris@hirtfamily.net>
  • Loading branch information
hahn-kev and megahirt authored Aug 14, 2024
1 parent 104ce40 commit d0b61c6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci+cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ jobs:

build-and-test:
runs-on: ${{ matrix.os }}
timeout-minutes: 360
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}
cancel-in-progress: true

steps:
- name: Checkout
Expand Down
9 changes: 7 additions & 2 deletions src/LibChorus/VcsDrivers/Mercurial/HgResumeRestApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ public HgResumeApiResponse Execute(string method, HgResumeApiParameters request,
[Obsolete] public string UserName => null;
[Obsolete] public string Password => null;

public HgResumeApiResponse Execute(string method, HgResumeApiParameters parameters, byte[] contentToSend, int secondsBeforeTimeout)
public static string FormatUrl(Uri uri, string method, HgResumeApiParameters parameters)
{
string queryString = parameters.BuildQueryString();
Url = string.Format("{0}://{1}/api/v{2}/{3}?{4}", _url.Scheme, _url.Host, ApiVersion, method, queryString);
return $"{uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)}/api/v{ApiVersion}/{method}{queryString}";
}

public HgResumeApiResponse Execute(string method, HgResumeApiParameters parameters, byte[] contentToSend, int secondsBeforeTimeout)
{
Url = FormatUrl(_url, method, parameters);
var req = (HttpWebRequest) WebRequest.Create(Url);
req.UserAgent = $"HgResume v{ApiVersion}";
req.PreAuthenticate = true;
Expand Down
10 changes: 9 additions & 1 deletion src/LibChorus/VcsDrivers/Mercurial/IApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public HgResumeApiParameters()
// used only by getRevisions API
public int Quantity { get; set; }

/// <summary>
/// returns a query string, prefixed with a '?' unless there are no parameters
/// </summary>
/// <returns></returns>
public string BuildQueryString()
{
string query = "";
string query = "?";
if (StartOfWindow >= 0)
{
query += String.Format("offset={0}&", StartOfWindow);
Expand Down Expand Up @@ -77,6 +81,10 @@ public string BuildQueryString()
{
query += String.Format("repoId={0}&", RepoId);
}
if (query == "?")
{
return "";
}
return query.TrimEnd('&');
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Chorus.VcsDrivers.Mercurial;
using NUnit.Framework;

Expand All @@ -21,5 +22,36 @@ public void Constructor_LanguageForgeUrl_IdentityAndProjectIdSetCorrectly()
Assert.That(api.Host, Is.EqualTo("hg.languageforge.org"));
Assert.That(api.ProjectId, Is.EqualTo("kyu-dictionary"));
}

[Test]
public void FormatUrl_FormatsCorrectlyWithEmptyParameters()
{
Assert.That(HgResumeRestApiServer.FormatUrl(
new Uri("https://hg.languageforge.org:1234/projects/kyu-dictionary"),
"foo",
new HgResumeApiParameters()),
Is.EqualTo("https://hg.languageforge.org:1234/api/v03/foo"));
}

[Test]
public void FormatUrl_FormatsCorrectlyWithParameters()
{
//this test is overly specific as the order of the parameters is not important, however this is much simpler to write.
Assert.That(HgResumeRestApiServer.FormatUrl(
new Uri("https://hg.languageforge.org:1234/projects/kyu-dictionary"),
"foo",
new HgResumeApiParameters
{
StartOfWindow = 10,
ChunkSize = 20,
BundleSize = 30,
Quantity = 40,
TransId = "transId",
BaseHashes = new[] { "baseHash1", "baseHash2" },
RepoId = "repoId"
}),
Is.EqualTo(
"https://hg.languageforge.org:1234/api/v03/foo?offset=10&chunkSize=20&bundleSize=30&quantity=40&transId=transId&baseHashes[]=baseHash1&baseHashes[]=baseHash2&repoId=repoId"));
}
}
}

0 comments on commit d0b61c6

Please sign in to comment.