mirror of
https://github.com/apple/swift-log
synced 2026-11-27 04:14:20 +00:00
[contains work from @ianpartridge and @weissi] Motivation: For an easier migration path, it is probably useful to ship a `0.x` version of `swift-log` that is compatible with Swift 4. It can't use any of the features that Swift 5 brings and therefore the Swift 4 version will have a slightly reduced feature set: - log messages will be `String` - logging metadata values will be `String` only (no dictionaries, arrays, ...) That means, if you use the Swift 4 version of swift-log carefully (only use string literals), your migration to the Swift 5 version should only be a matter of changing your `Package.swift`. Modifications: - remove all string interpolation and use `String` directly Result: - we can release a 0.x version that supports Swift 4 Support Swift 4.1 (#40) * Support Swift 4.1 * Set swift-tools-version to 4.0
55 lines
2.0 KiB
Swift
55 lines
2.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Logging API open source project
|
|
//
|
|
// Copyright (c) 2018-2019 Apple Inc. and the Swift Logging API project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of Swift Logging API project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
import Dispatch
|
|
@testable import Logging
|
|
import XCTest
|
|
|
|
class MDCTest: XCTestCase {
|
|
func test1() throws {
|
|
// bootstrap with our test logger
|
|
let logging = TestLogging()
|
|
LoggingSystem.bootstrapInternal(logging.make)
|
|
|
|
// run the program
|
|
MDC.global["foo"] = .string("bar")
|
|
let group = DispatchGroup()
|
|
for r in 5 ... 10 {
|
|
group.enter()
|
|
DispatchQueue(label: "mdc-test-queue-\(r)").async {
|
|
let add = 999
|
|
let remove = 123
|
|
for i in 0 ... add {
|
|
MDC.global["key-\(i)"] = .string("value-\(i)")
|
|
}
|
|
for i in 0 ... remove {
|
|
MDC.global["key-\(i)"] = nil
|
|
}
|
|
XCTAssertEqual(add - remove, MDC.global.metadata.count, "expected number of entries to match")
|
|
for i in remove + 1 ... add {
|
|
XCTAssertNotNil(MDC.global["key-\(i)"], "expecting value for key-\(i)")
|
|
}
|
|
for i in 0 ... remove {
|
|
XCTAssertNil(MDC.global["key-\(i)"], "not expecting value for key-\(i)")
|
|
}
|
|
MDC.global.clear()
|
|
group.leave()
|
|
}
|
|
}
|
|
group.wait()
|
|
XCTAssertEqual(MDC.global["foo"], .string("bar"), "expecting to find top items")
|
|
MDC.global["foo"] = nil
|
|
XCTAssertTrue(MDC.global.metadata.isEmpty, "MDC should be empty")
|
|
}
|
|
}
|