mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-16 03:48:09 +00:00
Move functions into Functions namespace (#2176)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class AgentCanSchedule {
|
||||
private readonly ILogTracer _log;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class AgentCommands {
|
||||
private readonly ILogTracer _log;
|
@ -3,7 +3,7 @@ using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class AgentEvents {
|
||||
private readonly ILogTracer _log;
|
@ -3,7 +3,7 @@ using Azure.Storage.Sas;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class AgentRegistration {
|
||||
private readonly ILogTracer _log;
|
||||
@ -127,7 +127,7 @@ public class AgentRegistration {
|
||||
await _context.NodeOperations.Delete(existingNode);
|
||||
}
|
||||
|
||||
var node = new Node(
|
||||
var node = new Service.Node(
|
||||
PoolName: poolName,
|
||||
PoolId: pool.PoolId,
|
||||
MachineId: machineId,
|
@ -2,7 +2,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class ContainersFunction {
|
||||
private readonly ILogTracer _logger;
|
@ -3,7 +3,7 @@ using Azure.Storage.Sas;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class Download {
|
||||
private readonly IEndpointAuthorization _auth;
|
@ -4,7 +4,7 @@ using System.Threading;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class Info {
|
||||
private readonly IOnefuzzContext _context;
|
@ -1,23 +1,20 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
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 IEndpointAuthorization _auth;
|
||||
private readonly IOnefuzzContext _context;
|
||||
|
||||
public NodeFunction(ILogTracer log, IEndpointAuthorization auth, IOnefuzzContext context) {
|
||||
public Node(ILogTracer log, IEndpointAuthorization auth, IOnefuzzContext context) {
|
||||
_log = log;
|
||||
_auth = auth;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
private static readonly EntityConverter _entityConverter = new();
|
||||
|
||||
[Function("Node")]
|
||||
public Async.Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "GET", "PATCH", "POST", "DELETE")] HttpRequestData req) {
|
||||
return _auth.CallIfUser(req, r => r.Method switch {
|
||||
@ -63,7 +60,7 @@ public class NodeFunction {
|
||||
return await RequestHandling.Ok(req, nodes.Select(NodeToNodeSearchResult));
|
||||
}
|
||||
|
||||
private static NodeSearchResult NodeToNodeSearchResult(Node node) {
|
||||
private static NodeSearchResult NodeToNodeSearchResult(Service.Node node) {
|
||||
return new NodeSearchResult(
|
||||
PoolId: node.PoolId,
|
||||
PoolName: node.PoolName,
|
@ -2,7 +2,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class QueueFileChanges {
|
||||
// The number of time the function will be retried if an error occurs
|
@ -2,7 +2,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
|
||||
public class QueueNodeHearbeat {
|
@ -2,7 +2,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class QueueProxyHearbeat {
|
||||
private readonly ILogTracer _log;
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class QueueSignalREvents {
|
||||
private readonly ILogTracerFactory _loggerFactory;
|
@ -3,7 +3,7 @@ using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
|
||||
public class QueueTaskHearbeat {
|
@ -2,7 +2,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class QueueWebhooks {
|
||||
private readonly ILogTracer _log;
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
|
||||
public class TimerDaily {
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class TimerProxy {
|
||||
private readonly ILogTracer _logger;
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class TimerRepro {
|
||||
private readonly ILogTracer _log;
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class TimerRetention {
|
||||
private readonly TimeSpan RETENTION_POLICY = TimeSpan.FromDays(18 * 30);
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
|
||||
public class TimerTasks {
|
@ -1,4 +1,4 @@
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
namespace Microsoft.OneFuzz.Service.Functions;
|
||||
|
||||
public class TimerWorkers {
|
||||
ILogTracer _log;
|
@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
|
@ -3,10 +3,13 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
|
||||
using Node = Microsoft.OneFuzz.Service.Node;
|
||||
|
||||
namespace IntegrationTests;
|
||||
|
||||
[Trait("Category", "Live")]
|
||||
@ -25,12 +28,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
: base(output, storage) { }
|
||||
|
||||
// shared helper variables (per-test)
|
||||
readonly Guid jobId = Guid.NewGuid();
|
||||
readonly Guid taskId = Guid.NewGuid();
|
||||
readonly Guid machineId = Guid.NewGuid();
|
||||
readonly PoolName poolName = PoolName.Parse($"pool-{Guid.NewGuid()}");
|
||||
readonly Guid poolId = Guid.NewGuid();
|
||||
readonly string poolVersion = $"version-{Guid.NewGuid()}";
|
||||
readonly Guid _jobId = Guid.NewGuid();
|
||||
readonly Guid _taskId = Guid.NewGuid();
|
||||
readonly Guid _machineId = Guid.NewGuid();
|
||||
readonly PoolName _poolName = PoolName.Parse($"pool-{Guid.NewGuid()}");
|
||||
readonly Guid _poolId = Guid.NewGuid();
|
||||
readonly string _poolVersion = $"version-{Guid.NewGuid()}";
|
||||
|
||||
[Fact]
|
||||
public async Async.Task Authorization_IsRequired() {
|
||||
@ -67,18 +70,18 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task WorkerDone_WithSuccessfulResult_ForRunningTask_MarksTaskAsStopping() {
|
||||
await Context.InsertAll(
|
||||
new Node(poolName, machineId, poolId, poolVersion),
|
||||
new Node(_poolName, _machineId, _poolId, _poolVersion),
|
||||
// task state is running
|
||||
new Task(jobId, taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 100))));
|
||||
new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 100))));
|
||||
|
||||
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
|
||||
var func = new AgentEvents(Logger, auth, Context);
|
||||
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
MachineId: _machineId,
|
||||
Event: new WorkerEvent(Done: new WorkerDoneEvent(
|
||||
TaskId: taskId,
|
||||
TaskId: _taskId,
|
||||
ExitStatus: new ExitStatus(Code: 0, Signal: 0, Success: true),
|
||||
"stderr",
|
||||
"stdout")));
|
||||
@ -95,18 +98,18 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task WorkerDone_WithFailedResult_ForRunningTask_MarksTaskAsStoppingAndErrored() {
|
||||
await Context.InsertAll(
|
||||
new Node(poolName, machineId, poolId, poolVersion),
|
||||
new Node(_poolName, _machineId, _poolId, _poolVersion),
|
||||
// task state is running
|
||||
new Task(jobId, taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 100))));
|
||||
new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 100))));
|
||||
|
||||
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
|
||||
var func = new AgentEvents(Logger, auth, Context);
|
||||
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
MachineId: _machineId,
|
||||
Event: new WorkerEvent(Done: new WorkerDoneEvent(
|
||||
TaskId: taskId,
|
||||
TaskId: _taskId,
|
||||
ExitStatus: new ExitStatus(Code: 0, Signal: 0, Success: false), // unsuccessful result
|
||||
"stderr",
|
||||
"stdout")));
|
||||
@ -122,18 +125,18 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task WorkerDone_ForNonStartedTask_MarksTaskAsFailed() {
|
||||
await Context.InsertAll(
|
||||
new Node(poolName, machineId, poolId, poolVersion),
|
||||
new Node(_poolName, _machineId, _poolId, _poolVersion),
|
||||
// task state is scheduled, not running
|
||||
new Task(jobId, taskId, TaskState.Scheduled, Os.Linux,
|
||||
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 100))));
|
||||
new Task(_jobId, _taskId, TaskState.Scheduled, Os.Linux,
|
||||
new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 100))));
|
||||
|
||||
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
|
||||
var func = new AgentEvents(Logger, auth, Context);
|
||||
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
MachineId: _machineId,
|
||||
Event: new WorkerEvent(Done: new WorkerDoneEvent(
|
||||
TaskId: taskId,
|
||||
TaskId: _taskId,
|
||||
ExitStatus: new ExitStatus(0, 0, true),
|
||||
"stderr",
|
||||
"stdout")));
|
||||
@ -151,13 +154,13 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task WorkerRunning_ForMissingTask_ReturnsError() {
|
||||
await Context.InsertAll(
|
||||
new Node(poolName, machineId, poolId, poolVersion));
|
||||
new Node(_poolName, _machineId, _poolId, _poolVersion));
|
||||
|
||||
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
|
||||
var func = new AgentEvents(Logger, auth, Context);
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
Event: new WorkerEvent(Running: new WorkerRunningEvent(taskId)));
|
||||
MachineId: _machineId,
|
||||
Event: new WorkerEvent(Running: new WorkerRunningEvent(_taskId)));
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
|
||||
Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
|
||||
@ -167,14 +170,14 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task WorkerRunning_ForMissingNode_ReturnsError() {
|
||||
await Context.InsertAll(
|
||||
new Task(jobId, taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 0))));
|
||||
new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 0))));
|
||||
|
||||
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
|
||||
var func = new AgentEvents(Logger, auth, Context);
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
Event: new WorkerEvent(Running: new WorkerRunningEvent(taskId)));
|
||||
MachineId: _machineId,
|
||||
Event: new WorkerEvent(Running: new WorkerRunningEvent(_taskId)));
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
|
||||
Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
|
||||
@ -184,15 +187,15 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task WorkerRunning_HappyPath() {
|
||||
await Context.InsertAll(
|
||||
new Node(poolName, machineId, poolId, poolVersion),
|
||||
new Task(jobId, taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(jobId, null, new TaskDetails(TaskType.Coverage, 0))));
|
||||
new Node(_poolName, _machineId, _poolId, _poolVersion),
|
||||
new Task(_jobId, _taskId, TaskState.Running, Os.Linux,
|
||||
new TaskConfig(_jobId, null, new TaskDetails(TaskType.Coverage, 0))));
|
||||
|
||||
var auth = new TestEndpointAuthorization(RequestType.Agent, Logger, Context);
|
||||
var func = new AgentEvents(Logger, auth, Context);
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
Event: new WorkerEvent(Running: new WorkerRunningEvent(taskId)));
|
||||
MachineId: _machineId,
|
||||
Event: new WorkerEvent(Running: new WorkerRunningEvent(_taskId)));
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
|
||||
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
||||
@ -212,16 +215,16 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
Async.Task.Run(async () => {
|
||||
// there should be a node-task with correct values
|
||||
var nodeTask = await Context.NodeTasksOperations.SearchAll().SingleAsync();
|
||||
Assert.Equal(machineId, nodeTask.MachineId);
|
||||
Assert.Equal(taskId, nodeTask.TaskId);
|
||||
Assert.Equal(_machineId, nodeTask.MachineId);
|
||||
Assert.Equal(_taskId, nodeTask.TaskId);
|
||||
Assert.Equal(NodeTaskState.Running, nodeTask.State);
|
||||
}),
|
||||
Async.Task.Run(async () => {
|
||||
// there should be a task-event with correct values
|
||||
var taskEvent = await Context.TaskEventOperations.SearchAll().SingleAsync();
|
||||
Assert.Equal(taskId, taskEvent.TaskId);
|
||||
Assert.Equal(machineId, taskEvent.MachineId);
|
||||
Assert.Equal(new WorkerEvent(Running: new WorkerRunningEvent(taskId)), taskEvent.EventData);
|
||||
Assert.Equal(_taskId, taskEvent.TaskId);
|
||||
Assert.Equal(_machineId, taskEvent.MachineId);
|
||||
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 func = new AgentEvents(Logger, auth, Context);
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
MachineId: _machineId,
|
||||
Event: new NodeStateUpdate(NodeState.Init));
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
|
||||
@ -243,12 +246,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task NodeStateUpdate_CanTransitionFromInitToReady() {
|
||||
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 func = new AgentEvents(Logger, auth, Context);
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
MachineId: _machineId,
|
||||
Event: new NodeStateUpdate(NodeState.Ready));
|
||||
|
||||
var result = await func.Run(TestHttpRequestData.FromJson("POST", data));
|
||||
@ -261,12 +264,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task NodeStateUpdate_BecomingFree_StopsNode_IfMarkedForReimage() {
|
||||
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 func = new AgentEvents(Logger, auth, Context);
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
MachineId: _machineId,
|
||||
Event: new NodeStateUpdate(NodeState.Free));
|
||||
|
||||
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:
|
||||
var messages = await Context.NodeMessageOperations.SearchAll().ToListAsync();
|
||||
Assert.Contains(messages, msg =>
|
||||
msg.MachineId == machineId &&
|
||||
msg.MachineId == _machineId &&
|
||||
msg.Message.Stop == new StopNodeCommand());
|
||||
}));
|
||||
}
|
||||
@ -290,12 +293,12 @@ public abstract class AgentEventsTestsBase : FunctionTestBase {
|
||||
[Fact]
|
||||
public async Async.Task NodeStateUpdate_BecomingFree_StopsNode_IfMarkedForDeletion() {
|
||||
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 func = new AgentEvents(Logger, auth, Context);
|
||||
var data = new NodeStateEnvelope(
|
||||
MachineId: machineId,
|
||||
MachineId: _machineId,
|
||||
Event: new NodeStateUpdate(NodeState.Free));
|
||||
|
||||
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:
|
||||
var messages = await Context.NodeMessageOperations.SearchAll().ToListAsync();
|
||||
Assert.Contains(messages, msg =>
|
||||
msg.MachineId == machineId &&
|
||||
msg.MachineId == _machineId &&
|
||||
msg.Message.Stop == new StopNodeCommand());
|
||||
}));
|
||||
}
|
||||
|
@ -3,9 +3,11 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
using Node = Microsoft.OneFuzz.Service.Node;
|
||||
|
||||
namespace IntegrationTests;
|
||||
|
||||
|
@ -7,6 +7,7 @@ using System.Net;
|
||||
using Azure.Storage.Blobs;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
|
@ -4,6 +4,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
|
@ -3,6 +3,7 @@ using System;
|
||||
using System.Net;
|
||||
using IntegrationTests.Fakes;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
|
@ -8,6 +8,7 @@ using Microsoft.OneFuzz.Service;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Async = System.Threading.Tasks;
|
||||
using NodeFunction = Microsoft.OneFuzz.Service.Functions.Node;
|
||||
|
||||
namespace IntegrationTests.Functions;
|
||||
|
||||
|
@ -3,71 +3,72 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.Functions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
public class TimerReproTests {
|
||||
private ILogTracer log;
|
||||
private Mock<IOnefuzzContext> mockCtx;
|
||||
private Mock<IReproOperations> mockReproOperations;
|
||||
private readonly ILogTracer _log;
|
||||
private readonly Mock<IOnefuzzContext> _mockCtx;
|
||||
private readonly Mock<IReproOperations> _mockReproOperations;
|
||||
|
||||
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>());
|
||||
mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork))
|
||||
_mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork))
|
||||
.Returns(AsyncEnumerable.Empty<Repro>());
|
||||
|
||||
log = new Mock<ILogTracer>().Object;
|
||||
_log = new Mock<ILogTracer>().Object;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async System.Threading.Tasks.Task NoExpiredRepros() {
|
||||
mockReproOperations.Setup(x => x.SearchExpired())
|
||||
_mockReproOperations.Setup(x => x.SearchExpired())
|
||||
.Returns(AsyncEnumerable.Empty<Repro>());
|
||||
|
||||
mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(mockReproOperations.Object);
|
||||
_mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(_mockReproOperations.Object);
|
||||
|
||||
var timerRepro = new TimerRepro(log, mockCtx.Object);
|
||||
var timerRepro = new TimerRepro(_log, _mockCtx.Object);
|
||||
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]
|
||||
public async System.Threading.Tasks.Task ExpiredRepro() {
|
||||
mockReproOperations.Setup(x => x.SearchExpired())
|
||||
_mockReproOperations.Setup(x => x.SearchExpired())
|
||||
.Returns(new List<Repro> {
|
||||
GenerateRepro()
|
||||
}.ToAsyncEnumerable());
|
||||
|
||||
mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(mockReproOperations.Object);
|
||||
_mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(_mockReproOperations.Object);
|
||||
|
||||
var timerRepro = new TimerRepro(log, mockCtx.Object);
|
||||
var timerRepro = new TimerRepro(_log, _mockCtx.Object);
|
||||
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]
|
||||
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>());
|
||||
|
||||
mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(mockReproOperations.Object);
|
||||
_mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(_mockReproOperations.Object);
|
||||
|
||||
var timerRepro = new TimerRepro(log, mockCtx.Object);
|
||||
var timerRepro = new TimerRepro(_log, _mockCtx.Object);
|
||||
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]
|
||||
@ -75,24 +76,24 @@ public class TimerReproTests {
|
||||
var expiredVm = GenerateRepro();
|
||||
var notExpiredVm = GenerateRepro();
|
||||
|
||||
mockReproOperations.Setup(x => x.SearchExpired())
|
||||
_mockReproOperations.Setup(x => x.SearchExpired())
|
||||
.Returns(new List<Repro> {
|
||||
expiredVm
|
||||
}.ToAsyncEnumerable());
|
||||
|
||||
mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork))
|
||||
_mockReproOperations.Setup(x => x.SearchStates(VmStateHelper.NeedsWork))
|
||||
.Returns(new List<Repro> {
|
||||
expiredVm,
|
||||
notExpiredVm
|
||||
}.ToAsyncEnumerable());
|
||||
|
||||
mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(mockReproOperations.Object);
|
||||
_mockCtx.Setup(x => x.ReproOperations)
|
||||
.Returns(_mockReproOperations.Object);
|
||||
|
||||
var timerRepro = new TimerRepro(log, mockCtx.Object);
|
||||
var timerRepro = new TimerRepro(_log, _mockCtx.Object);
|
||||
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() {
|
||||
|
Reference in New Issue
Block a user