Polarion Web 服务上的并行执行

问题描述 投票:0回答:1

我想使用 C# 在 Polarion 测试管理 Web 服务上实现并行执行。谁能帮助我实现这一目标。

我尝试了以下方法,但每次运行时都会出现不同的异常。有时执行成功没有错误,但有时却出错。

var parallelOptions = new ParallelOptions 
{ 
    MaxDegreeOfParallelism = 3 
};

UploadDataTask task = new UploadDataTask();

Parallel.For(0, testRecordsAfterAdding.Length, parallelOptions, i =>
{
    var test = testRecordsAfterAdding[i];
    task.UploadData(test, i, con, idTestCase, ruUri, testRun, textTestRun, userUriExecuted);
    Console.WriteLine("Thread" + Thread.CurrentThread.ManagedThreadId);
});
c# web-services parallel-processing polarion
1个回答
0
投票

由于您没有提供有关 UploadDataTask 和发生错误的详细信息,我认为分配正确的文件 ID 时出现了问题。

看这里:

// Attachment DTO
public record Attachment(string title, string fileName, string id = "", byte[] data = null);


// Upload a file to all test runs
var testRuns = new List<TestRun>();

...

testRuns.AsParallel().ForAll(
        run => {
            var fileId = $"{run.Id}_{DateTime.Now:yyyyMMdd_hhmmss}_{fileName}";
            var attachment = new Attachment("File Title", fileName, fileId, File.ReadAllBytes(filePath));
            run.Attachments.Add(attachment);
            _testManagementService.UpdateTestRun(run);
        });

// UpdateTestRun method executes:
public void AddAttachmentToTestRun(string testRunUri, Attachment attachment) {
    try {
        _connection.TestManagement.addAttachmentToTestRun(testRunUri, attachment.FileName, attachment.Title, attachment.Data);
    } catch (Exception ex) {
        _log.Error($"Could not add attachment {attachment.Title} to test run.");
        _log.Error(ex);
    }
}

旁注:我建议您使用 REST API,因为 Web 服务接口已在版本 2404 中置于维护模式。

© www.soinside.com 2019 - 2024. All rights reserved.