Emcee

Форк
0
/
InitTestArgFileCommand.swift 
182 строки · 9.7 Кб
1
import ArgLib
2
import BuildArtifacts
3
import CommonTestModels
4
import DeveloperDirModels
5
import EmceeDI
6
import EmceeLogging
7
import Foundation
8
import MetricsExtensions
9
import PathLib
10
import PluginSupport
11
import QueueModels
12
import SimulatorPoolModels
13
import SocketModels
14
import TestArgFile
15
import TestDestination
16
import WorkerCapabilities
17
import WorkerCapabilitiesModels
18

19
public final class InitTestArgFileCommand: Command {
20
    public let name = "initTestArgFile"
21
    public let description = "Generates a sample test arg file"
22
    public let arguments: Arguments = [
23
        ArgumentDescriptions.output.asRequired,
24
    ]
25
    
26
    private let di: DI
27
    
28
    public init(
29
        di: DI
30
    ) throws {
31
        self.di = di
32
    }
33
    
34
    public func run(payload: CommandPayload) throws {
35
        let logger = try di.get(ContextualLogger.self)
36
        
37
        let outputPath: AbsolutePath = try payload.expectedSingleTypedValue(argumentName: ArgumentDescriptions.output.name)
38
        
39
        let testDestination = TestDestination.iOSSimulator(deviceType: "iPhone X", version: "15.1")
40
        
41
        let testArgFile = TestArgFile(
42
            entries: [
43
                TestArgFileEntry(
44
                    buildArtifacts: AppleBuildArtifacts.iosUiTests(
45
                        xcTestBundle: XcTestBundle(
46
                            location: TestBundleLocation(
47
                                .remoteUrl(
48
                                    URL(string: "http://storage.example.com/build1234/FunctionalTests.zip#FunctionalTests.xctest")!,
49
                                    nil
50
                                )
51
                            ),
52
                            testDiscoveryMode: .parseFunctionSymbols
53
                        ),
54
                        appBundle: AppBundleLocation(
55
                            .remoteUrl(
56
                                URL(string: "http://storage.example.com/build1234/MainApp.zip#MainApp.app")!,
57
                                [
58
                                    "X-Header": "You can append arbitrary headers if needed, e.g. for auth",
59
                                    "X-Comment": "Also please read https://github.com/avito-tech/Emcee/wiki/URL-Handling",
60
                                ]
61
                            )
62
                        ),
63
                        runner: RunnerAppLocation(
64
                            .remoteUrl(
65
                                URL(string: "http://storage.example.com/build1234/FunctionalTests-Runner.zip#FunctionalTests-Runner.app")!,
66
                                nil
67
                            )
68
                        ),
69
                        additionalApplicationBundles: [
70
                            AdditionalAppBundleLocation(
71
                                .remoteUrl(
72
                                    URL(string: "http://storage.example.com/build1234/FunctionalTests.zip#FunctionalTests.xctest")!,
73
                                    [
74
                                        "X-Comment": "URL to ZIP file containing addtional .app bundle. Usually this is useful for XC UI tests, which can run additinal apps during test execution",
75
                                    ]
76
                                )
77
                            )
78
                        ]
79
                    ),
80
                    developerDir: DeveloperDir.useXcode(
81
                        CFBundleShortVersionString: "13.1 - e.g. for Xcode 13.1. Provide here an Xcode version which should be used"
82
                    ),
83
                    environment: [
84
                        "SomeEnvName": "These envs will be available from inside tests, usually via ProcessInfo.environment API",
85
                    ],
86
                    userInsertedLibraries: [],
87
                    numberOfRetries: 0,
88
                    testRetryMode: .retryThroughQueue,
89
                    logCapturingMode: .onlyCrashLogs,
90
                    runnerWasteCleanupPolicy: .clean,
91
                    pluginLocations: [
92
                        AppleTestPluginLocation(
93
                            .remoteUrl(
94
                                URL(string: "http://storage.example.com/emceeplugins/MyPlugin.zip#MyPlugin.emceeplugin")!,
95
                                [
96
                                    "X-Comment": "URL to ZIP file containing Emcee plugin bundle with .emceeplugin extension",
97
                                    "X-Docs": "Please refer to https://github.com/avito-tech/Emcee/wiki/Plugins for more information about plugins",
98
                                ]
99
                            )
100
                        ),
101
                    ],
102
                    scheduleStrategy: TestArgFileDefaultValues.scheduleStrategy,
103
                    simulatorOperationTimeouts: SimulatorOperationTimeouts(
104
                        create: 60,
105
                        boot: 180,
106
                        delete: 30,
107
                        shutdown: 30,
108
                        automaticSimulatorShutdown: 600,
109
                        automaticSimulatorDelete: 200
110
                    ),
111
                    simulatorSettings: TestArgFileDefaultValues.simulatorSettings,
112
                    testDestination: testDestination,
113
                    testTimeoutConfiguration: TestArgFileDefaultValues.testTimeoutConfiguration,
114
                    testAttachmentLifetime: TestArgFileDefaultValues.testAttachmentLifetime,
115
                    testsToRun: [
116
                        .testName(TestName(className: "ClassName", methodName: "test")),
117
                        .testName(TestName(className: "ClassName", methodName: "testSpecificTestMethodName__youCanRepeatTestNamesMultipleTimes__toMakeTestRunSeveralTimes")),
118
                        .testName(TestName(className: "ClassName", methodName: "testSpecificTestMethodName__youCanRepeatTestNamesMultipleTimes__toMakeTestRunSeveralTimes")),
119
                        .allDiscoveredTests,
120
                    ],
121
                    workerCapabilityRequirements: [
122
                        WorkerCapabilityRequirement(
123
                            capabilityName: XcodeCapabilitiesProvider.workerCapabilityName(
124
                                shortVersion: "13.1 —— this requirement enforces that tests will only run on workers satisfying this Xcode version requirement."
125
                            ),
126
                            constraint: .present
127
                        )
128
                    ]
129
                )
130
            ],
131
            prioritizedJob: PrioritizedJob(
132
                analyticsConfiguration: AnalyticsConfiguration(
133
                    graphiteConfiguration: MetricConfiguration(
134
                        socketAddress: SocketAddress(
135
                            host: "graphite.example.com — this is a host name which runs Graphite instance, and its port. Please also refer to https://github.com/avito-tech/Emcee/wiki/Graphite",
136
                            port: 42
137
                        ),
138
                        metricPrefix: "some.prefix.for.emcee"
139
                    ),
140
                    statsdConfiguration: MetricConfiguration(
141
                        socketAddress: SocketAddress(
142
                            host: "statsd.example.com — this is a host name which runs Statsd instance, and its port. Please also refer to https://github.com/avito-tech/Emcee/wiki/Graphite",
143
                            port: 1234
144
                        ),
145
                        metricPrefix: "some.prefix.for.emcee"
146
                    ),
147
                    kibanaConfiguration: KibanaConfiguration(
148
                        endpoints: [
149
                            URL(string: "http://kibana.example.com:12345/")!,
150
                        ],
151
                        indexPattern: "emcee-index-16112021-"
152
                    ),
153
                    persistentMetricsJobId: "UnitTests - set this to allow reporting top-level metrics for jobs with this persistent ID. Useful for statsd metrics which describe top level behaviour of these jobs.",
154
                    metadata: [
155
                        "ciBranchName": "SomeBranchNameWhereTestsAreRunning",
156
                        "whatisthis": "These values are used for logging purposes. E.g. in Kibana, you can then filter logs by these values.",
157
                    ]
158
                ),
159
                jobGroupId: JobGroupId(
160
                    "This is an unique value, e.g. uuid, but it should be common of multiple jobs that are part of the same job group. Please refer to https://github.com/avito-tech/Emcee/wiki/Test-Arg-File#schema."
161
                ),
162
                jobGroupPriority: Priority(750),
163
                jobId: JobId("This is unique job id. Emcee queue will store test results under this key. Please note, that running additional test run with the same job id will APPEND the test results into previous run. It is better to change this value for each run. UUID can be safely used for this purposes, probably with some human readable additions for ease of understanding, e.g. PR1234_UnitTest_F80A8B88-A209-4694-8847-DC797642655C"),
164
                jobPriority: .medium
165
            ),
166
            testDestinationConfigurations: [
167
                TestDestinationConfiguration(
168
                    testDestination: testDestination,
169
                    reportOutput: ReportOutput(
170
                        junit: "Absolute path to where junit specific for _this test destination_ should be created. --junit will contain the complete junit report.",
171
                        tracingReport: "Absolute path to where Chrome trace specific for _this test destination_ should be created. --trace will contain the complete trace for the whole test run."
172
                    )
173
                ),
174
            ]
175
        )
176
        
177
        let data = try JSONEncoder.pretty().encode(testArgFile)
178
        try data.write(to: outputPath.fileUrl)
179
        
180
        logger.info("Generated test arg file stored at \(outputPath)")
181
    }
182
}
183

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.