Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SelfUpdate Flow when Package is provided in Message #2926

Merged
merged 34 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5914c1f
wip
luketomlinson Oct 12, 2023
50037b7
wip fork selfupdater
luketomlinson Oct 12, 2023
10a2768
wip
luketomlinson Oct 12, 2023
69e0707
working
luketomlinson Oct 13, 2023
5b58e67
wip l0
luketomlinson Oct 13, 2023
bca63dc
Add back another test
luketomlinson Oct 13, 2023
3fa3934
Add back another test
luketomlinson Oct 13, 2023
0d8ee42
revert runnerversion changes
luketomlinson Oct 13, 2023
5114f75
format
luketomlinson Oct 16, 2023
9774819
more formatting
luketomlinson Oct 16, 2023
19dae98
whitespace
luketomlinson Oct 16, 2023
1836e5c
pr feedback
luketomlinson Oct 17, 2023
1ab0621
fix test
luketomlinson Oct 17, 2023
54e80cc
Simplify and use RunnerRefreshMessage
luketomlinson Nov 1, 2023
95875b1
.
luketomlinson Nov 1, 2023
76c5c6e
format
luketomlinson Nov 1, 2023
73a9274
fix tests
luketomlinson Nov 1, 2023
9e7d45b
fix
luketomlinson Nov 3, 2023
0e5052e
feedback
luketomlinson Nov 3, 2023
607a26a
format
luketomlinson Nov 3, 2023
b61c5ea
.
luketomlinson Nov 3, 2023
d5c084c
.
luketomlinson Nov 3, 2023
87f8cb3
feedback
luketomlinson Nov 3, 2023
09a228a
format
luketomlinson Nov 3, 2023
7249c05
.
luketomlinson Nov 3, 2023
73d9aa7
cleanup
luketomlinson Nov 3, 2023
2dd14e9
cleanup
luketomlinson Nov 7, 2023
efbbfda
fix field names
luketomlinson Nov 13, 2023
0cfe109
pr feedback
luketomlinson Nov 13, 2023
457cc22
feedback
luketomlinson Nov 13, 2023
673f9d9
delete dead code
luketomlinson Nov 13, 2023
ff87f73
.
luketomlinson Nov 13, 2023
8b0d538
fix debug condition
luketomlinson Nov 13, 2023
2be4992
Merge branch 'main' into new-update-flow
luketomlinson Nov 13, 2023
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
Prev Previous commit
Next Next commit
Add back another test
  • Loading branch information
luketomlinson committed Oct 13, 2023
commit 3fa3934296584b5a7c66fa2a787e6491e24b8b42
103 changes: 50 additions & 53 deletions src/Test/L0/Listener/SelfUpdaterV2L0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,59 +182,56 @@ public async void TestSelfUpdateAsync_DownloadRetry()
}
}

// [Fact]
// [Trait("Level", "L0")]
// [Trait("Category", "Runner")]
// public async void TestSelfUpdateAsync_ValidateHash()
// {
// try
// {
// await FetchLatestRunner();
// Assert.NotNull(_packageUrl);
// Assert.NotNull(_trimmedPackages);
// Environment.SetEnvironmentVariable("RUNNER_L0_OVERRIDEBINDIR", Path.GetFullPath(Path.Combine(TestUtil.GetSrcPath(), "..", "_layout", "bin")));
// using (var hc = new TestHostContext(this))
// {
// hc.GetTrace().Info(_packageUrl);
// hc.GetTrace().Info(StringUtil.ConvertToJson(_trimmedPackages));

// //Arrange
// var updater = new Runner.Listener.SelfUpdaterV2();
// hc.SetSingleton<ITerminal>(_term.Object);
// hc.SetSingleton<IRunnerServer>(_runnerServer.Object);
// hc.SetSingleton<IConfigurationStore>(_configStore.Object);
// hc.SetSingleton<IHttpClientHandlerFactory>(new HttpClientHandlerFactory());

// _runnerServer.Setup(x => x.GetPackageAsync("agent", BuildConstants.RunnerPackage.PackageName, "2.999.0", true, It.IsAny<CancellationToken>()))
// .Returns(Task.FromResult(new PackageMetadata() { Platform = BuildConstants.RunnerPackage.PackageName, Version = new PackageVersion("2.999.0"), DownloadUrl = _packageUrl, HashValue = "bad_hash" }));

// var p1 = new ProcessInvokerWrapper();
// p1.Initialize(hc);
// var p2 = new ProcessInvokerWrapper();
// p2.Initialize(hc);
// var p3 = new ProcessInvokerWrapper();
// p3.Initialize(hc);
// hc.EnqueueInstance<IProcessInvoker>(p1);
// hc.EnqueueInstance<IProcessInvoker>(p2);
// hc.EnqueueInstance<IProcessInvoker>(p3);
// updater.Initialize(hc);

// var packageMetadata = new PackageMetadata() { Platform = BuildConstants.RunnerPackage.PackageName, Version = new PackageVersion("2.999.0"), DownloadUrl = _packageUrl };
// var message = new AgentRefreshMessage(1, "2.999.0")
// {
// PackageMetadata = packageMetadata
// };


// var ex = await Assert.ThrowsAsync<Exception>(() => updater.SelfUpdate(_refreshMessage, _jobDispatcher.Object, true, hc.RunnerShutdownToken));
// Assert.Contains("did not match expected Runner Hash", ex.Message);
// }
// }
// finally
// {
// Environment.SetEnvironmentVariable("RUNNER_L0_OVERRIDEBINDIR", null);
// }
// }
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Runner")]
public async void TestSelfUpdateAsync_ValidateHash()
{
try
{
await FetchLatestRunner();
Assert.NotNull(_packageUrl);
Assert.NotNull(_trimmedPackages);
Environment.SetEnvironmentVariable("RUNNER_L0_OVERRIDEBINDIR", Path.GetFullPath(Path.Combine(TestUtil.GetSrcPath(), "..", "_layout", "bin")));
using (var hc = new TestHostContext(this))
{
hc.GetTrace().Info(_packageUrl);
hc.GetTrace().Info(StringUtil.ConvertToJson(_trimmedPackages));

//Arrange
var updater = new Runner.Listener.SelfUpdaterV2();
hc.SetSingleton<ITerminal>(_term.Object);
hc.SetSingleton<IRunnerServer>(_runnerServer.Object);
hc.SetSingleton<IConfigurationStore>(_configStore.Object);
hc.SetSingleton<IHttpClientHandlerFactory>(new HttpClientHandlerFactory());

var p1 = new ProcessInvokerWrapper();
p1.Initialize(hc);
var p2 = new ProcessInvokerWrapper();
p2.Initialize(hc);
var p3 = new ProcessInvokerWrapper();
p3.Initialize(hc);
hc.EnqueueInstance<IProcessInvoker>(p1);
hc.EnqueueInstance<IProcessInvoker>(p2);
hc.EnqueueInstance<IProcessInvoker>(p3);
updater.Initialize(hc);

var packageMetadata = new PackageMetadata() { Platform = BuildConstants.RunnerPackage.PackageName, Version = new PackageVersion("2.999.0"), DownloadUrl = _packageUrl, HashValue = "bad_hash" };
var message = new AgentRefreshMessage(1, "2.999.0")
{
PackageMetadata = packageMetadata
};


var ex = await Assert.ThrowsAsync<Exception>(() => updater.SelfUpdate(message, _jobDispatcher.Object, true, hc.RunnerShutdownToken));
Assert.Contains("did not match expected Runner Hash", ex.Message);
}
}
finally
{
Environment.SetEnvironmentVariable("RUNNER_L0_OVERRIDEBINDIR", null);
}
}
}
}
#endif