Skip to content

Commit

Permalink
typo in shutdown not shudown
Browse files Browse the repository at this point in the history
Also added test for CredentialProviderSelector shutdown
  • Loading branch information
adam-fowler committed Dec 3, 2020
1 parent c74aae5 commit 743e1ef
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Sources/SotoCore/Credential/CredentialProviderSelector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ import NIO
import NIOConcurrencyHelpers
import SotoSignerV4

/// Protocol for CredentialProvider that uses an internal CredentialProvider
///
/// When conforming to this protocol once you ahve the internal provider it should be supplying to
/// the startupPromise and you should set `internalProvider` when the setupPromise
/// result is available.
/// ```
/// init(providers: [CredentialProviderFactory], context: CredentialProviderFactory.Context) {
/// self.startupPromise = context.eventLoop.makePromise(of: CredentialProvider.self)
/// self.startupPromise.futureResult.whenSuccess { result in
/// self.internalProvider = result
/// }
/// self.setupInternalProvider(providers: providers, context: context)
///}
/// ```
protocol CredentialProviderSelector: CredentialProvider, AnyObject {
/// promise to find a credential provider
var startupPromise: EventLoopPromise<CredentialProvider> { get }
Expand All @@ -39,7 +53,7 @@ extension CredentialProviderSelector {
}
}

func shudown(on eventLoop: EventLoop) -> EventLoopFuture<Void> {
func shutdown(on eventLoop: EventLoop) -> EventLoopFuture<Void> {
return self.startupPromise.futureResult.flatMap { provider in
provider.shutdown(on: eventLoop)
}.hop(to: eventLoop)
Expand Down
38 changes: 38 additions & 0 deletions Tests/SotoCoreTests/Credential/CredentialProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import AsyncHTTPClient
import Logging
import NIO
import NIOConcurrencyHelpers
@testable import SotoCore
import SotoTestUtils
import XCTest
Expand Down Expand Up @@ -100,4 +101,41 @@ class CredentialProviderTests: XCTestCase {
XCTAssertEqual(error as? CredentialProviderError, .noProvider)
}
}

func testCredentialSelectorShutdown() {
class TestCredentialProvider: CredentialProvider {
var active = true

func getCredential(on eventLoop: EventLoop, logger: Logger) -> EventLoopFuture<Credential> {
return eventLoop.makeSucceededFuture(StaticCredential(accessKeyId: "", secretAccessKey: ""))
}

func shutdown(on eventLoop: EventLoop) -> EventLoopFuture<Void> {
self.active = false
return eventLoop.makeSucceededFuture(())
}

deinit {
XCTAssertEqual(active, false)
}
}
class CredentialProviderOwner: CredentialProviderSelector {
/// promise to find a credential provider
let startupPromise: EventLoopPromise<CredentialProvider>
let lock = Lock()
var _internalProvider: CredentialProvider?

init(eventLoop: EventLoop) {
self.startupPromise = eventLoop.makePromise(of: CredentialProvider.self)
self.startupPromise.futureResult.whenSuccess { result in
self.internalProvider = result
}
self.startupPromise.succeed(TestCredentialProvider())
}
}
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer { XCTAssertNoThrow(try elg.syncShutdownGracefully())}
let provider = CredentialProviderOwner(eventLoop: elg.next())
XCTAssertNoThrow(try provider.shutdown(on: elg.next()).wait())
}
}

0 comments on commit 743e1ef

Please sign in to comment.