func testExtraLargeLogMessage()

in TwitterLoggingServiceTests/TLSLoggingSwiftTests.swift [287:320]


    func testExtraLargeLogMessage()
    {
        var longMessage = "This is a long message that will exceed 16KB so that we can test that it will be discarded."
        while (longMessage.count < 16 * 1024) {
            longMessage += longMessage
        }

        var expectation: XCTestExpectation
        let service = TLSLoggingService()
        let delegate = TLSLoggingSwiftTestServiceDelegate()
        let outputStream = TLSLoggingSwiftTestOutputStream()

        service.delegate = delegate
        outputStream.shouldPrint = false
        service.addOutputStream(outputStream)

        // will log
        service.maximumSafeMessageLength = 0
        expectation = self.expectation(forNotification: NSNotification.Name(rawValue: Notification.Name.LoggingSwiftTestOutputStreamNotification.rawValue), object: nil, handler: nil)
        TLSLogString(service, TLSLogLevel.error, "AnyChannel", #file, #function, #line, nil, TLSLogMessageOptions(), longMessage)
        self.waitForExpectations(timeout: 10, handler: nil)

        // won't log
        service.maximumSafeMessageLength = 16 * 1024
        expectation = self.expectation(forNotification: NSNotification.Name(rawValue: Notification.Name.LoggingSwiftTestDiscardedMessageNotification.rawValue), object: nil, handler: nil)
        TLSLogString(service, TLSLogLevel.error, "AnyChannel", #file, #function, #line, nil, TLSLogMessageOptions(), longMessage)
        self.waitForExpectations(timeout: 10, handler: nil)

        // just to avoid the compiler warning :(
        // can't do `(void)expectation;` like in C/ObjC
        if expectation.isKind(of: XCTestExpectation.self) {

        }
    }