Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncBoot will no longer try booting server again if it is already booted #3195

Merged
merged 4 commits into from
May 21, 2024

Conversation

RussBaz
Copy link
Contributor

@RussBaz RussBaz commented May 19, 2024

These changes are now available in 4.100.2

The synchronous boot function skips running the lifecycle handlers if the server is already booted. However, the async version ignored this check. I have added a small fix to add this check again.

@RussBaz RussBaz requested review from 0xTim and gwynne as code owners May 19, 2024 20:35
Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.46%. Comparing base (11cdb29) to head (6e83023).
Report is 24 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3195      +/-   ##
==========================================
+ Coverage   76.86%   77.46%   +0.59%     
==========================================
  Files         211      210       -1     
  Lines        8119     8089      -30     
==========================================
+ Hits         6241     6266      +25     
+ Misses       1878     1823      -55     
Files Coverage Δ
Sources/Vapor/Application.swift 84.30% <100.00%> (-3.56%) ⬇️

... and 94 files with indirect coverage changes

Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you add a test to ensure this works?

    func testBootDoesNotTriggerHandlerMultipleTimes() throws {
        let app = Application(.testing)
        defer { app.shutdown() }
        
        final class Handler: LifecycleHandler, Sendable {
            let bootCount = NIOLockedValueBox(0)
            func willBoot(_ application: Application) throws {
                bootCount.withLockedValue { $0 += 1 }
            }
        }
        
        let handler = Handler()
        app.lifecycle.use(handler)
        
        try app.boot()
        try app.boot()

        XCTAssertEqual(handler.bootCount.withLockedValue({ $0 }), 1)
    }
    
    func testAsyncBootDoesNotTriggerHandlerMultipleTimes() async throws {
        let app = try await Application.make(.testing)
        
        final class Handler: LifecycleHandler, Sendable {
            let bootCount = NIOLockedValueBox(0)
            func willBoot(_ application: Application) throws {
                bootCount.withLockedValue { $0 += 1 }
            }
        }
        
        let handler = Handler()
        app.lifecycle.use(handler)
        
        try await app.asyncBoot()
        try await app.asyncBoot()

        XCTAssertEqual(handler.bootCount.withLockedValue({ $0 }), 1)
        
        try await app.asyncShutdown()
    }

In ApplicationTests should work

@RussBaz
Copy link
Contributor Author

RussBaz commented May 21, 2024

Done. Please have a look again.

Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@0xTim 0xTim added the semver-patch Internal changes only label May 21, 2024
@0xTim 0xTim enabled auto-merge (squash) May 21, 2024 20:18
@0xTim 0xTim merged commit 2c185b7 into vapor:main May 21, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch Internal changes only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants