pb33f / libopenapi

libopenapi is a fully featured, high performance OpenAPI 3.1, 3.0 and Swagger parser, library, validator and toolkit for golang applications.
https://pb33f.io/libopenapi/
Other
482 stars 64 forks source link

Add RW Lock to allComponentSchemas to Prevent Data Race Error #344

Closed califlower closed 3 weeks ago

califlower commented 1 month ago
codecov[bot] commented 4 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.61%. Comparing base (5ac8657) to head (5c3c79d). Report is 7 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #344 +/- ## ========================================== - Coverage 99.62% 99.61% -0.01% ========================================== Files 165 165 Lines 21050 21064 +14 ========================================== + Hits 20971 20983 +12 - Misses 74 76 +2 Partials 5 5 ``` | [Flag](https://app.codecov.io/gh/pb33f/libopenapi/pull/344/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pb33f) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/pb33f/libopenapi/pull/344/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pb33f) | `99.61% <100.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pb33f#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

califlower commented 4 weeks ago

I can add a test here, just wasn't sure about testing the race condition it was kind of difficult

califlower commented 4 weeks ago

I added a concurrent access test and a nil test. That should keep the coverage where it was at before

califlower commented 3 weeks ago

RIP. Doesn't seem like codecov is correct :<

daveshanley commented 3 weeks ago

The codecov is correct, I checked out your branch and this is what happens after running all tests.

Screenshot 2024-10-29 at 10 30 30 AM

The problem is the test.

func TestSpecIndex_GetAllComponentSchemas_NilIndex(t *testing.T) {
    index := &SpecIndex{}
    schemas := index.GetAllComponentSchemas()
    assert.Nil(t, schemas, "Expected GetAllComponentSchemas to return nil when index is nil")
}

index cannot be nil here, it will never be nil. To fix it:

func TestSpecIndex_GetAllComponentSchemas_NilIndex(t *testing.T) {
    var index *SpecIndex
    schemas := index.GetAllComponentSchemas()
    assert.Nil(t, schemas, "Expected GetAllComponentSchemas to return nil when index is nil")
}
califlower commented 3 weeks ago

Ah my bad. Thank you for fixing it and merging! Really appreciate it!