Move functions into Functions namespace (#2176)

This commit is contained in:
George Pollard
2022-07-22 08:46:31 +12:00
committed by GitHub
parent 08fb29fc6b
commit 94db49995f
29 changed files with 112 additions and 103 deletions

View File

@ -1,7 +1,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class AgentCanSchedule { public class AgentCanSchedule {
private readonly ILogTracer _log; private readonly ILogTracer _log;

View File

@ -1,7 +1,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class AgentCommands { public class AgentCommands {
private readonly ILogTracer _log; private readonly ILogTracer _log;

View File

@ -3,7 +3,7 @@ using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class AgentEvents { public class AgentEvents {
private readonly ILogTracer _log; private readonly ILogTracer _log;

View File

@ -3,7 +3,7 @@ using Azure.Storage.Sas;
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class AgentRegistration { public class AgentRegistration {
private readonly ILogTracer _log; private readonly ILogTracer _log;
@ -127,7 +127,7 @@ public class AgentRegistration {
await _context.NodeOperations.Delete(existingNode); await _context.NodeOperations.Delete(existingNode);
} }
var node = new Node( var node = new Service.Node(
PoolName: poolName, PoolName: poolName,
PoolId: pool.PoolId, PoolId: pool.PoolId,
MachineId: machineId, MachineId: machineId,

View File

@ -2,7 +2,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class ContainersFunction { public class ContainersFunction {
private readonly ILogTracer _logger; private readonly ILogTracer _logger;

View File

@ -3,7 +3,7 @@ using Azure.Storage.Sas;
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class Download { public class Download {
private readonly IEndpointAuthorization _auth; private readonly IEndpointAuthorization _auth;

View File

@ -4,7 +4,7 @@ using System.Threading;
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class Info { public class Info {
private readonly IOnefuzzContext _context; private readonly IOnefuzzContext _context;

View File

@ -1,23 +1,20 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class NodeFunction { public class Node {
private readonly ILogTracer _log; private readonly ILogTracer _log;
private readonly IEndpointAuthorization _auth; private readonly IEndpointAuthorization _auth;
private readonly IOnefuzzContext _context; private readonly IOnefuzzContext _context;
public NodeFunction(ILogTracer log, IEndpointAuthorization auth, IOnefuzzContext context) { public Node(ILogTracer log, IEndpointAuthorization auth, IOnefuzzContext context) {
_log = log; _log = log;
_auth = auth; _auth = auth;
_context = context; _context = context;
} }
private static readonly EntityConverter _entityConverter = new();
[Function("Node")] [Function("Node")]
public Async.Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "GET", "PATCH", "POST", "DELETE")] HttpRequestData req) { public Async.Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "GET", "PATCH", "POST", "DELETE")] HttpRequestData req) {
return _auth.CallIfUser(req, r => r.Method switch { return _auth.CallIfUser(req, r => r.Method switch {
@ -63,7 +60,7 @@ public class NodeFunction {
return await RequestHandling.Ok(req, nodes.Select(NodeToNodeSearchResult)); return await RequestHandling.Ok(req, nodes.Select(NodeToNodeSearchResult));
} }
private static NodeSearchResult NodeToNodeSearchResult(Node node) { private static NodeSearchResult NodeToNodeSearchResult(Service.Node node) {
return new NodeSearchResult( return new NodeSearchResult(
PoolId: node.PoolId, PoolId: node.PoolId,
PoolName: node.PoolName, PoolName: node.PoolName,

View File

@ -2,7 +2,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class QueueFileChanges { public class QueueFileChanges {
// The number of time the function will be retried if an error occurs // The number of time the function will be retried if an error occurs

View File

@ -2,7 +2,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class QueueNodeHearbeat { public class QueueNodeHearbeat {

View File

@ -2,7 +2,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class QueueProxyHearbeat { public class QueueProxyHearbeat {
private readonly ILogTracer _log; private readonly ILogTracer _log;

View File

@ -1,6 +1,6 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class QueueSignalREvents { public class QueueSignalREvents {
private readonly ILogTracerFactory _loggerFactory; private readonly ILogTracerFactory _loggerFactory;

View File

@ -3,7 +3,7 @@ using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class QueueTaskHearbeat { public class QueueTaskHearbeat {

View File

@ -2,7 +2,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class QueueWebhooks { public class QueueWebhooks {
private readonly ILogTracer _log; private readonly ILogTracer _log;

View File

@ -1,7 +1,7 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class TimerDaily { public class TimerDaily {

View File

@ -1,6 +1,6 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class TimerProxy { public class TimerProxy {
private readonly ILogTracer _logger; private readonly ILogTracer _logger;

View File

@ -1,6 +1,6 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class TimerRepro { public class TimerRepro {
private readonly ILogTracer _log; private readonly ILogTracer _log;

View File

@ -1,6 +1,6 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class TimerRetention { public class TimerRetention {
private readonly TimeSpan RETENTION_POLICY = TimeSpan.FromDays(18 * 30); private readonly TimeSpan RETENTION_POLICY = TimeSpan.FromDays(18 * 30);

View File

@ -1,6 +1,6 @@
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class TimerTasks { public class TimerTasks {

View File

@ -1,4 +1,4 @@
namespace Microsoft.OneFuzz.Service; namespace Microsoft.OneFuzz.Service.Functions;
public class TimerWorkers { public class TimerWorkers {
ILogTracer _log; ILogTracer _log;

View File

@ -1,6 +1,7 @@
using System.Net; using System.Net;
using IntegrationTests.Fakes; using IntegrationTests.Fakes;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using Async = System.Threading.Tasks; using Async = System.Threading.Tasks;

View File

@ -1,6 +1,7 @@
using System.Net; using System.Net;
using IntegrationTests.Fakes; using IntegrationTests.Fakes;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using Async = System.Threading.Tasks; using Async = System.Threading.Tasks;

View File

@ -3,10 +3,13 @@ using System.Linq;
using System.Net; using System.Net;
using IntegrationTests.Fakes; using IntegrationTests.Fakes;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using Async = System.Threading.Tasks; using Async = System.Threading.Tasks;
using Node = Microsoft.OneFuzz.Service.Node;
namespace IntegrationTests; namespace IntegrationTests;
[Trait("Category", "Live")] [Trait("Category", "Live")]
@ -25,12 +28,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
: base(output, storage) { } : base(output, storage) { }
// shared helper variables (per-test) // shared helper variables (per-test)
readonly Guid jobId = Guid.NewGuid(); readonly Guid _jobId = Guid.NewGuid();
readonly Guid taskId = Guid.NewGuid(); readonly Guid _taskId = Guid.NewGuid();
readonly Guid machineId = Guid.NewGuid(); readonly Guid _machineId = Guid.NewGuid();
readonly PoolName poolName = PoolName.Parse($"pool-{Guid.NewGuid()}"); readonly PoolName _poolName = PoolName.Parse($"pool-{Guid.NewGuid()}");
readonly Guid poolId = Guid.NewGuid(); readonly Guid _poolId = Guid.NewGuid();
readonly string poolVersion = $"version-{Guid.NewGuid()}"; readonly string _poolVersion = $"version-{Guid.NewGuid()}";
[Fact] [Fact]
public async Async.Task Authorization_IsRequired() { public async Async.Task Authorization_IsRequired() {
@ -67,18 +70,18 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task WorkerDone_WithSuccessfulResult_ForRunningTask_MarksTaskAsStopping() { public async Async.Task WorkerDone_WithSuccessfulResult_ForRunningTask_MarksTaskAsStopping() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion), new Node(_poolName, _machineId, _poolId, _poolVersion),
// task state is running // task state is running
new Task(jobId, taskId, TaskState.Running, Os.Linux, new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 100)))); new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 100))));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new WorkerEvent(Done: new WorkerDoneEvent( Event: new WorkerEvent(Done: new WorkerDoneEvent(
TaskId: taskId, TaskId: _taskId,
ExitStatus: new ExitStatus(Code: 0, Signal: 0, Success: true), ExitStatus: new ExitStatus(Code: 0, Signal: 0, Success: true),
"stderr", "stderr",
"stdout"))); "stdout")));
@ -95,18 +98,18 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task WorkerDone_WithFailedResult_ForRunningTask_MarksTaskAsStoppingAndErrored() { public async Async.Task WorkerDone_WithFailedResult_ForRunningTask_MarksTaskAsStoppingAndErrored() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion), new Node(_poolName, _machineId, _poolId, _poolVersion),
// task state is running // task state is running
new Task(jobId, taskId, TaskState.Running, Os.Linux, new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 100)))); new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 100))));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new WorkerEvent(Done: new WorkerDoneEvent( Event: new WorkerEvent(Done: new WorkerDoneEvent(
TaskId: taskId, TaskId: _taskId,
ExitStatus: new ExitStatus(Code: 0, Signal: 0, Success: false), // unsuccessful result ExitStatus: new ExitStatus(Code: 0, Signal: 0, Success: false), // unsuccessful result
"stderr", "stderr",
"stdout"))); "stdout")));
@ -122,18 +125,18 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task WorkerDone_ForNonStartedTask_MarksTaskAsFailed() { public async Async.Task WorkerDone_ForNonStartedTask_MarksTaskAsFailed() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion), new Node(_poolName, _machineId, _poolId, _poolVersion),
// task state is scheduled, not running // task state is scheduled, not running
new Task(jobId, taskId, TaskState.Scheduled, Os.Linux, new Task(_jobId, _taskId, TaskState.Scheduled, Os.Linux,
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 100)))); new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 100))));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new WorkerEvent(Done: new WorkerDoneEvent( Event: new WorkerEvent(Done: new WorkerDoneEvent(
TaskId: taskId, TaskId: _taskId,
ExitStatus: new ExitStatus(0, 0, true), ExitStatus: new ExitStatus(0, 0, true),
"stderr", "stderr",
"stdout"))); "stdout")));
@ -151,13 +154,13 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task WorkerRunning_ForMissingTask_ReturnsError() { public async Async.Task WorkerRunning_ForMissingTask_ReturnsError() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion)); new Node(_poolName, _machineId, _poolId, _poolVersion));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new WorkerEvent(Running: new WorkerRunningEvent(taskId))); Event: new WorkerEvent(Running: new WorkerRunningEvent(_taskId)));
var result = await func.Run(TestHttpRequestData.FromJson("POST", data)); var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
@ -167,14 +170,14 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task WorkerRunning_ForMissingNode_ReturnsError() { public async Async.Task WorkerRunning_ForMissingNode_ReturnsError() {
await Context.InsertAll( await Context.InsertAll(
new Task(jobId, taskId, TaskState.Running, Os.Linux, new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 0)))); new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 0))));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new WorkerEvent(Running: new WorkerRunningEvent(taskId))); Event: new WorkerEvent(Running: new WorkerRunningEvent(_taskId)));
var result = await func.Run(TestHttpRequestData.FromJson("POST", data)); var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
@ -184,15 +187,15 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task WorkerRunning_HappyPath() { public async Async.Task WorkerRunning_HappyPath() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion), new Node(_poolName, _machineId, _poolId, _poolVersion),
new Task(jobId, taskId, TaskState.Running, Os.Linux, new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 0)))); new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 0))));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new WorkerEvent(Running: new WorkerRunningEvent(taskId))); Event: new WorkerEvent(Running: new WorkerRunningEvent(_taskId)));
var result = await func.Run(TestHttpRequestData.FromJson("POST", data)); var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal(HttpStatusCode.OK, result.StatusCode);
@ -212,16 +215,16 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
Async.Task.Run(async () => { Async.Task.Run(async () => {
// there should be a node-task with correct values // there should be a node-task with correct values
var nodeTask = await Context.NodeTasksOperations.SearchAll().SingleAsync(); var nodeTask = await Context.NodeTasksOperations.SearchAll().SingleAsync();
Assert.Equal(machineId, nodeTask.MachineId); Assert.Equal(_machineId, nodeTask.MachineId);
Assert.Equal(taskId, nodeTask.TaskId); Assert.Equal(_taskId, nodeTask.TaskId);
Assert.Equal(NodeTaskState.Running, nodeTask.State); Assert.Equal(NodeTaskState.Running, nodeTask.State);
}), }),
Async.Task.Run(async () => { Async.Task.Run(async () => {
// there should be a task-event with correct values // there should be a task-event with correct values
var taskEvent = await Context.TaskEventOperations.SearchAll().SingleAsync(); var taskEvent = await Context.TaskEventOperations.SearchAll().SingleAsync();
Assert.Equal(taskId, taskEvent.TaskId); Assert.Equal(_taskId, taskEvent.TaskId);
Assert.Equal(machineId, taskEvent.MachineId); Assert.Equal(_machineId, taskEvent.MachineId);
Assert.Equal(new WorkerEvent(Running: new WorkerRunningEvent(taskId)), taskEvent.EventData); Assert.Equal(new WorkerEvent(Running: new WorkerRunningEvent(_taskId)), taskEvent.EventData);
})); }));
} }
@ -232,7 +235,7 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new NodeStateUpdate(NodeState.Init)); Event: new NodeStateUpdate(NodeState.Init));
var result = await func.Run(TestHttpRequestData.FromJson("POST", data)); var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
@ -243,12 +246,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task NodeStateUpdate_CanTransitionFromInitToReady() { public async Async.Task NodeStateUpdate_CanTransitionFromInitToReady() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion, State: NodeState.Init)); new Node(_poolName, _machineId, _poolId, _poolVersion, State: NodeState.Init));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new NodeStateUpdate(NodeState.Ready)); Event: new NodeStateUpdate(NodeState.Ready));
var result = await func.Run(TestHttpRequestData.FromJson("POST", data)); var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
@ -261,12 +264,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task NodeStateUpdate_BecomingFree_StopsNode_IfMarkedForReimage() { public async Async.Task NodeStateUpdate_BecomingFree_StopsNode_IfMarkedForReimage() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion, ReimageRequested: true)); new Node(_poolName, _machineId, _poolId, _poolVersion, ReimageRequested: true));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new NodeStateUpdate(NodeState.Free)); Event: new NodeStateUpdate(NodeState.Free));
var result = await func.Run(TestHttpRequestData.FromJson("POST", data)); var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
@ -282,7 +285,7 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
// the node should be told to stop: // the node should be told to stop:
var messages = await Context.NodeMessageOperations.SearchAll().ToListAsync(); var messages = await Context.NodeMessageOperations.SearchAll().ToListAsync();
Assert.Contains(messages, msg => Assert.Contains(messages, msg =>
msg.MachineId == machineId && msg.MachineId == _machineId &&
msg.Message.Stop == new StopNodeCommand()); msg.Message.Stop == new StopNodeCommand());
})); }));
} }
@ -290,12 +293,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
[Fact] [Fact]
public async Async.Task NodeStateUpdate_BecomingFree_StopsNode_IfMarkedForDeletion() { public async Async.Task NodeStateUpdate_BecomingFree_StopsNode_IfMarkedForDeletion() {
await Context.InsertAll( await Context.InsertAll(
new Node(poolName, machineId, poolId, poolVersion, DeleteRequested: true)); new Node(_poolName, _machineId, _poolId, _poolVersion, DeleteRequested: true));
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context); var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
var func = new AgentEvents(Logger, auth, Context); var func = new AgentEvents(Logger, auth, Context);
var data = new NodeStateEnvelope( var data = new NodeStateEnvelope(
MachineId: machineId, MachineId: _machineId,
Event: new NodeStateUpdate(NodeState.Free)); Event: new NodeStateUpdate(NodeState.Free));
var result = await func.Run(TestHttpRequestData.FromJson("POST", data)); var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
@ -311,7 +314,7 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
// the node should be told to stop: // the node should be told to stop:
var messages = await Context.NodeMessageOperations.SearchAll().ToListAsync(); var messages = await Context.NodeMessageOperations.SearchAll().ToListAsync();
Assert.Contains(messages, msg => Assert.Contains(messages, msg =>
msg.MachineId == machineId && msg.MachineId == _machineId &&
msg.Message.Stop == new StopNodeCommand()); msg.Message.Stop == new StopNodeCommand());
})); }));
} }

View File

@ -3,9 +3,11 @@ using System.Linq;
using System.Net; using System.Net;
using IntegrationTests.Fakes; using IntegrationTests.Fakes;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using Async = System.Threading.Tasks; using Async = System.Threading.Tasks;
using Node = Microsoft.OneFuzz.Service.Node;
namespace IntegrationTests; namespace IntegrationTests;

View File

@ -7,6 +7,7 @@ using System.Net;
using Azure.Storage.Blobs; using Azure.Storage.Blobs;
using IntegrationTests.Fakes; using IntegrationTests.Fakes;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;

View File

@ -4,6 +4,7 @@ using System.Net;
using System.Net.Http; using System.Net.Http;
using IntegrationTests.Fakes; using IntegrationTests.Fakes;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using Async = System.Threading.Tasks; using Async = System.Threading.Tasks;

View File

@ -3,6 +3,7 @@ using System;
using System.Net; using System.Net;
using IntegrationTests.Fakes; using IntegrationTests.Fakes;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using Async = System.Threading.Tasks; using Async = System.Threading.Tasks;

View File

@ -8,6 +8,7 @@ using Microsoft.OneFuzz.Service;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using Async = System.Threading.Tasks; using Async = System.Threading.Tasks;
using NodeFunction = Microsoft.OneFuzz.Service.Functions.Node;
namespace IntegrationTests.Functions; namespace IntegrationTests.Functions;

View File

@ -3,71 +3,72 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker;
using Microsoft.OneFuzz.Service; using Microsoft.OneFuzz.Service;
using Microsoft.OneFuzz.Service.Functions;
using Moq; using Moq;
using Xunit; using Xunit;
namespace Tests; namespace Tests;
public class TimerReproTests { public class TimerReproTests {
private ILogTracer log; private readonly ILogTracer _log;
private Mock<IOnefuzzContext> mockCtx; private readonly Mock<IOnefuzzContext> _mockCtx;
private Mock<IReproOperations> mockReproOperations; private readonly Mock<IReproOperations> _mockReproOperations;
public TimerReproTests() { public TimerReproTests() {
mockCtx = new Mock<IOnefuzzContext>(); _mockCtx = new Mock<IOnefuzzContext>();
mockReproOperations = new Mock<IReproOperations>(); _mockReproOperations = new Mock<IReproOperations>();
mockReproOperations.Setup(x => x.SearchExpired()) _mockReproOperations.Setup(x => x.SearchExpired())
.Returns(AsyncEnumerable.Empty<Repro>()); .Returns(AsyncEnumerable.Empty<Repro>());
mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork)) _mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork))
.Returns(AsyncEnumerable.Empty<Repro>()); .Returns(AsyncEnumerable.Empty<Repro>());
log = new Mock<ILogTracer>().Object; _log = new Mock<ILogTracer>().Object;
} }
[Fact] [Fact]
public async System.Threading.Tasks.Task NoExpiredRepros() { public async System.Threading.Tasks.Task NoExpiredRepros() {
mockReproOperations.Setup(x => x.SearchExpired()) _mockReproOperations.Setup(x => x.SearchExpired())
.Returns(AsyncEnumerable.Empty<Repro>()); .Returns(AsyncEnumerable.Empty<Repro>());
mockCtx.Setup(x => x.ReproOperations) _mockCtx.Setup(x => x.ReproOperations)
.Returns(mockReproOperations.Object); .Returns(_mockReproOperations.Object);
var timerRepro = new TimerRepro(log, mockCtx.Object); var timerRepro = new TimerRepro(_log, _mockCtx.Object);
await timerRepro.Run(new TimerInfo()); await timerRepro.Run(new TimerInfo());
mockReproOperations.Verify(x => x.Stopping(It.IsAny<Repro>()), Times.Never()); _mockReproOperations.Verify(x => x.Stopping(It.IsAny<Repro>()), Times.Never());
} }
[Fact] [Fact]
public async System.Threading.Tasks.Task ExpiredRepro() { public async System.Threading.Tasks.Task ExpiredRepro() {
mockReproOperations.Setup(x => x.SearchExpired()) _mockReproOperations.Setup(x => x.SearchExpired())
.Returns(new List<Repro> { .Returns(new List<Repro> {
GenerateRepro() GenerateRepro()
}.ToAsyncEnumerable()); }.ToAsyncEnumerable());
mockCtx.Setup(x => x.ReproOperations) _mockCtx.Setup(x => x.ReproOperations)
.Returns(mockReproOperations.Object); .Returns(_mockReproOperations.Object);
var timerRepro = new TimerRepro(log, mockCtx.Object); var timerRepro = new TimerRepro(_log, _mockCtx.Object);
await timerRepro.Run(new TimerInfo()); await timerRepro.Run(new TimerInfo());
mockReproOperations.Verify(x => x.Stopping(It.IsAny<Repro>()), Times.Once()); _mockReproOperations.Verify(x => x.Stopping(It.IsAny<Repro>()), Times.Once());
} }
[Fact] [Fact]
public async System.Threading.Tasks.Task NoNeedsWorkRepros() { public async System.Threading.Tasks.Task NoNeedsWorkRepros() {
mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork)) _mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork))
.Returns(AsyncEnumerable.Empty<Repro>()); .Returns(AsyncEnumerable.Empty<Repro>());
mockCtx.Setup(x => x.ReproOperations) _mockCtx.Setup(x => x.ReproOperations)
.Returns(mockReproOperations.Object); .Returns(_mockReproOperations.Object);
var timerRepro = new TimerRepro(log, mockCtx.Object); var timerRepro = new TimerRepro(_log, _mockCtx.Object);
await timerRepro.Run(new TimerInfo()); await timerRepro.Run(new TimerInfo());
mockReproOperations.Verify(x => x.ProcessStateUpdates(It.IsAny<Repro>(), It.IsAny<int>()), Times.Never()); _mockReproOperations.Verify(x => x.ProcessStateUpdates(It.IsAny<Repro>(), It.IsAny<int>()), Times.Never());
} }
[Fact] [Fact]
@ -75,24 +76,24 @@ public class TimerReproTests {
var expiredVm = GenerateRepro(); var expiredVm = GenerateRepro();
var notExpiredVm = GenerateRepro(); var notExpiredVm = GenerateRepro();
mockReproOperations.Setup(x => x.SearchExpired()) _mockReproOperations.Setup(x => x.SearchExpired())
.Returns(new List<Repro> { .Returns(new List<Repro> {
expiredVm expiredVm
}.ToAsyncEnumerable()); }.ToAsyncEnumerable());
mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork)) _mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork))
.Returns(new List<Repro> { .Returns(new List<Repro> {
expiredVm, expiredVm,
notExpiredVm notExpiredVm
}.ToAsyncEnumerable()); }.ToAsyncEnumerable());
mockCtx.Setup(x => x.ReproOperations) _mockCtx.Setup(x => x.ReproOperations)
.Returns(mockReproOperations.Object); .Returns(_mockReproOperations.Object);
var timerRepro = new TimerRepro(log, mockCtx.Object); var timerRepro = new TimerRepro(_log, _mockCtx.Object);
await timerRepro.Run(new TimerInfo()); await timerRepro.Run(new TimerInfo());
mockReproOperations.Verify(x => x.ProcessStateUpdates(It.IsAny<Repro>(), It.IsAny<int>()), Times.Once()); _mockReproOperations.Verify(x => x.ProcessStateUpdates(It.IsAny<Repro>(), It.IsAny<int>()), Times.Once());
} }
private static Repro GenerateRepro() { private static Repro GenerateRepro() {