Skip to content

Commit

Permalink
RUMM-334 Integration&Benchmark moved to Datadog.xcworkspace
Browse files Browse the repository at this point in the history
Integration and Benchmark projects are removed
  • Loading branch information
buranmert committed Apr 16, 2020
1 parent eea6171 commit 1bd4799
Show file tree
Hide file tree
Showing 48 changed files with 540 additions and 2,045 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
/.build
/.swiftpm
xcuserdata/

# SPM-generated .xcodedproj
Datadog.xcodeproj
10 changes: 10 additions & 0 deletions Datadog.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

344 changes: 343 additions & 1 deletion Datadog/Datadog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1140"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,38 +10,22 @@
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "REPOSITORY_ROOT=&quot;${SRCROOT}/../..&quot;&#10;cd &quot;${REPOSITORY_ROOT}&quot; &amp;&amp; ./tools/config/generate-http-server-mock-config.sh&#10;">
scriptText = "REPOSITORY_ROOT=&quot;${SRCROOT}/..&quot;&#10;cd &quot;${REPOSITORY_ROOT}&quot; &amp;&amp; ./tools/config/generate-http-server-mock-config.sh&#10;">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "610CCB88240527F300C4FE79"
BuildableName = "IntegrationTests.xctest"
BlueprintName = "IntegrationTests"
ReferencedContainer = "container:Integration.xcodeproj">
BlueprintIdentifier = "9E2FB2412447660E001C9B7B"
BuildableName = "DatadogIntegrationTests.xctest"
BlueprintName = "DatadogIntegrationTests"
ReferencedContainer = "container:Datadog.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
</ExecutionAction>
</PreActions>
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "610CCB72240527F100C4FE79"
BuildableName = "Integration.app"
BlueprintName = "Integration"
ReferencedContainer = "container:Integration.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
buildConfiguration = "Integration"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
Expand All @@ -50,14 +34,14 @@
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "REPOSITORY_ROOT=&quot;${SRCROOT}/../..&quot;&#10;cd &quot;${REPOSITORY_ROOT}&quot; &amp;&amp; ./instrumented-tests/http-server-mock/python/start_mock_server.py&amp;&#10;">
scriptText = "REPOSITORY_ROOT=&quot;${SRCROOT}/..&quot;&#10;cd &quot;${REPOSITORY_ROOT}&quot; &amp;&amp; ./instrumented-tests/http-server-mock/python/start_mock_server.py&amp;&#10;">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "610CCB88240527F300C4FE79"
BuildableName = "IntegrationTests.xctest"
BlueprintName = "IntegrationTests"
ReferencedContainer = "container:Integration.xcodeproj">
BlueprintIdentifier = "9E2FB2412447660E001C9B7B"
BuildableName = "DatadogIntegrationTests.xctest"
BlueprintName = "DatadogIntegrationTests"
ReferencedContainer = "container:Datadog.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
Expand All @@ -68,7 +52,16 @@
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "pkill -f start_mock_server.py&#10;">
scriptText = "pkill -f start_mock_server.py;&#10;">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9E2FB2412447660E001C9B7B"
BuildableName = "DatadogIntegrationTests.xctest"
BlueprintName = "DatadogIntegrationTests"
ReferencedContainer = "container:Datadog.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
</ExecutionAction>
</PostActions>
Expand All @@ -77,10 +70,10 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "610CCB88240527F300C4FE79"
BuildableName = "IntegrationTests.xctest"
BlueprintName = "IntegrationTests"
ReferencedContainer = "container:Integration.xcodeproj">
BlueprintIdentifier = "9E2FB2412447660E001C9B7B"
BuildableName = "DatadogIntegrationTests.xctest"
BlueprintName = "DatadogIntegrationTests"
ReferencedContainer = "container:Datadog.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
Expand All @@ -95,33 +88,13 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "610CCB72240527F100C4FE79"
BuildableName = "Integration.app"
BlueprintName = "Integration"
ReferencedContainer = "container:Integration.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "610CCB72240527F100C4FE79"
BuildableName = "Integration.app"
BlueprintName = "Integration"
ReferencedContainer = "container:Integration.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MOCK_SERVER_ADDRESS=
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ examples:
@echo "OK 👌"

benchmark:
@cd instrumented-tests/Benchmark && $(MAKE)
@xcodebuild -workspace "Datadog.xcworkspace" -scheme "DatadogIntegrationTests" test -destination "name=iPhone 11 Pro Max"

# Tests if current branch ships a valid SPM package.
test-spm:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import XCTest
import HTTPServerMock
@testable import Datadog

struct ServerConnectionError: Error {
let description: String
}

/// Shared server instance for all test cases.
private(set) var server: ServerMock! // swiftlint:disable:this implicitly_unwrapped_optional
/// Shared server session for all test cases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Datadog
import XCTest

class LoggingBenchmarkTests: BenchmarkTests {
private let message = "message"
private let message = "foobar-message"

func testCreatingOneLog() {
let logger = Logger.builder.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@ import Datadog
import HTTPServerMock
import XCTest

fileprivate func clearPersistedLogs() throws {
let logFilesSubdirectory = "com.datadoghq.logs/v1"
let cachesDirectoryURL = FileManager.default.urls(
for: .cachesDirectory,
in: .userDomainMask
).first
let subdirectoryURL = cachesDirectoryURL?.appendingPathComponent(
logFilesSubdirectory,
isDirectory: true
)
if let dirToRemove = subdirectoryURL {
try FileManager.default.removeItem(at: dirToRemove)
}
}

class LoggingIntegrationTests: IntegrationTests {
override func setUp() {
super.setUp()
try? clearPersistedLogs()
}

private struct Constants {
/// Time needed for logs to be uploaded to mock server.
static let logsDeliveryTime: TimeInterval = 30
Expand All @@ -20,7 +40,7 @@ class LoggingIntegrationTests: IntegrationTests {

// Initialize SDK
Datadog.initialize(
appContext: .init(mainBundle: .main),
appContext: .init(mainBundle: Bundle.init(for: type(of: self))),
configuration: Datadog.Configuration.builderUsing(clientToken: "client-token")
.set(logsEndpoint: .custom(url: serverSession.recordingURL.absoluteString))
.build()
Expand Down Expand Up @@ -82,7 +102,7 @@ class LoggingIntegrationTests: IntegrationTests {
matcher.assertServiceName(equals: "service-name")
matcher.assertLoggerName(equals: "logger-name")
matcher.assertLoggerVersion(matches: { version in version.split(separator: ".").count == 3 })
matcher.assertApplicationVersion(equals: "1.0.0")
matcher.assertApplicationVersion(equals: "1.0")
matcher.assertThreadName(equals: "main")
matcher.assertAttributes(
equal: [
Expand Down
24 changes: 24 additions & 0 deletions Tests/DatadogIntegrationTests/TestHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// TestHelpers.swift
// IntegrationTests
//
// Created by Mert Buran on 15/04/2020.
// Copyright © 2020 Datadog. All rights reserved.
//

import Foundation

func clearPersistedLogs() throws {
let logFilesSubdirectory = "com.datadoghq.logs/v1"
let cachesDirectoryURL = FileManager.default.urls(
for: .cachesDirectory,
in: .userDomainMask
).first
let subdirectoryURL = cachesDirectoryURL?.appendingPathComponent(
logFilesSubdirectory,
isDirectory: true
)
if let dirToRemove = subdirectoryURL {
try FileManager.default.removeItem(at: dirToRemove)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// LoggingIOBenchmarkTests.swift
// DatadogTests
//
// Created by Mert Buran on 15/04/2020.
// Copyright © 2020 Datadog. All rights reserved.
//

import XCTest
@testable import Datadog

class LoggingIOBenchmarkTests: XCTestCase {
// swiftlint:disable implicitly_unwrapped_optional
private var queue: DispatchQueue!
private var directory: Directory!
private var strategy: LogsPersistenceStrategy!
// swiftlint:enable implicitly_unwrapped_optional

override func setUp() {
super.setUp()
self.queue = DispatchQueue(label: "com.datadoghq.benchmark-logs-io", target: .global(qos: .utility))
self.directory = try! Directory(withSubdirectoryPath: "logging-benchmark")
self.strategy = .default(in: directory, using: SystemDateProvider(), readWriteQueue: queue)
XCTAssertTrue(try! directory.files().count == 0)
}

override func tearDown() {
try! FileManager.default.removeItem(at: directory.url)
queue = nil
directory = nil
strategy = nil
super.tearDown()
}

func testWrittingLogsOnDisc() throws {
let writer = strategy.writer
let log = createRandomizedLog()

measure {
writer.write(value: log)
queue.sync {} // wait to complete async write
}
}

func testReadingLogsFromDisc() throws {
let writer = strategy.writer
let reader = strategy.reader

while try directory.files().count < 10 { // `measureMetrics {}` is fired 10 times so 10 batch files are required
writer.write(value: createRandomizedLog())
queue.sync {} // wait to complete async write
}

// Wait enough time for `reader` to accept the youngest batch file
Thread.sleep(forTimeInterval: LogsPersistenceStrategy.Constants.minFileAgeForRead + 0.1)

measureMetrics([.wallClockTime], automaticallyStartMeasuring: false) {
self.startMeasuring()
let batch = reader.readNextBatch()
self.stopMeasuring()

XCTAssertNotNil(batch, "Not enough batch files were created for this benchmark.")

if let batch = batch {
reader.markBatchAsRead(batch)
}
}
}

// MARK: - Helpers

private func createRandomizedLog() -> Log {
return Log(
date: Date(),
status: .info,
message: "message \(Int.random(in: 0..<100))",
serviceName: "service-name",
loggerName: "logger-name",
loggerVersion: "0.0.0",
threadName: "main",
applicationVersion: "0.0.0",
userInfo: .init(id: "abc-123", name: "foo", email: "foo@bar.com"),
networkConnectionInfo: .init(
reachability: .yes,
availableInterfaces: [.cellular],
supportsIPv4: true,
supportsIPv6: true,
isExpensive: false,
isConstrained: false
),
mobileCarrierInfo: nil,
attributes: ["attribute": EncodableValue("value")],
tags: ["tag:value"]
)
}
}
5 changes: 5 additions & 0 deletions Tests/DatadogTests/Helpers/TestsDirectory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import Foundation
@testable import Datadog

func clearPersistedLogs() throws {
let directory = try Directory(withSubdirectoryPath: LogsPersistenceStrategy.Constants.logFilesSubdirectory)
try FileManager.default.removeItem(at: directory.url)
}

/// Creates `Directory` pointing to unique subfolder in `/var/folders/`.
/// Does not create the subfolder - it must be later created with `.create()`.
func obtainUniqueTemporaryDirectory() -> Directory {
Expand Down
Loading

0 comments on commit 1bd4799

Please sign in to comment.