public void StatusShallRunThrough() { var mockClient = new Mock <IJobsClient>(); var mockLogger = new Mock <ILogger <ClaraJobsApi> >(); var jobId = Guid.NewGuid().ToString("N"); var jobDate = DateTime.UtcNow; JobId.TryParse(jobId, out JobId jobIdObj); mockClient.Setup(p => p.GetStatus(It.IsAny <JobId>())) .ReturnsAsync(new JobDetails { JobId = jobIdObj, JobState = JobState.Pending, JobStatus = Nvidia.Clara.Platform.JobStatus.Healthy, DateCreated = jobDate, DateStarted = jobDate, DateStopped = jobDate, JobPriority = JobPriority.Higher, Name = "name" }); var service = new ClaraJobsApi( mockClient.Object, mockLogger.Object); service.Status(jobId).Wait(); mockClient.Verify( p => p.GetStatus(It.IsAny <JobId>()), Times.Exactly(1)); mockLogger.VerifyLogging(LogLevel.Error, Times.Never()); mockLogger.VerifyLogging(LogLevel.Information, Times.Once()); }
public void Status_ShallThrowOnBadPipelineId() { var mockClient = new Mock <IJobsClient>(); var mockLogger = new Mock <ILogger <ClaraJobsApi> >(); mockClient.Setup(p => p.GetStatus(It.IsAny <JobId>())); var service = new ClaraJobsApi(mockClient.Object, mockLogger.Object); var jobId = "bad job id has spaces"; var exception = Assert.Throws <AggregateException>(() => { service.Status(jobId).Wait(); }); Assert.IsType <ArgumentException>(exception.InnerException); mockClient.Verify( p => p.GetStatus(It.IsAny <JobId>()), Times.Never()); mockLogger.VerifyLogging(LogLevel.Error, Times.Exactly(1)); }
public void Status_ShallRespectRetryPolicyOnFailure() { var mockClient = new Mock <IJobsClient>(); var mockLogger = new Mock <ILogger <ClaraJobsApi> >(); mockClient.Setup(p => p.GetStatus(It.IsAny <JobId>())) .Throws(new RpcException(Status.DefaultCancelled)); var service = new ClaraJobsApi(mockClient.Object, mockLogger.Object); var jobId = Guid.NewGuid().ToString("N"); var exception = Assert.Throws <AggregateException>(() => { service.Status(jobId).Wait(); }); Assert.IsType <RpcException>(exception.InnerException); mockClient.Verify( p => p.GetStatus(It.IsAny <JobId>()), Times.Exactly(2)); mockLogger.VerifyLogging(LogLevel.Error, Times.Exactly(1)); }