cashapp / misk

Microservice Kontainer
https://cashapp.github.io/misk/
Apache License 2.0
407 stars 170 forks source link

Use MapBinder in KInstallOnceModuleTest #3353

Closed damar-block closed 5 months ago

damar-block commented 5 months ago

The existing test didn't fail if you changed the module back to a KAbstractModule. The new test does and confirms the failure mode as well.

adrw commented 5 months ago

If you change L28 to KAbstractModule() you now get the expected failure.

My understanding looking at the code is that installed modules are deduplicated by Guice and the default KAbstractModule doesn't have a predictable equals or hash to support that which allows modules to be installed in duplicate leading to failures further into the Guice lifecycle when it parses the bindings.

Unable to create injector, see the following errors:

1) [Guice/DuplicateMapKey]: Duplicate key "key" found in Map<String, KInstallOnceModuleTest$TestValue>.

Duplicates:
  Key: "key"
  Bound at:
    1 : KInstallOnceModuleTest$TestInstallOnceModule.configure(KInstallOnceModuleTest.kt:31)
      \_ installed by: MiskTestExtension$beforeEach$module$1 -> KInstallOnceModuleTest$TestModule -> KInstallOnceModuleTest$TestInstallOnceModule
    2 : KInstallOnceModuleTest$TestInstallOnceModule.configure(KInstallOnceModuleTest.kt:31)
      \_ installed by: MiskTestExtension$beforeEach$module$1 -> KInstallOnceModuleTest$TestModule -> KInstallOnceModuleTest$TestInstallOnceModule

MapBinder declared at:
  KInstallOnceModuleTest$TestInstallOnceModule.configure(KInstallOnceModuleTest.kt:41)
      \_ installed by: MiskTestExtension$beforeEach$module$1 -> KInstallOnceModuleTest$TestModule -> KInstallOnceModuleTest$TestInstallOnceModule -> RealMapBinder

1 error

======================
Full classname legend:
======================
KInstallOnceModuleTest$TestInstallOnceModule: "misk.inject.KInstallOnceModuleTest$TestInstallOnceModule"
KInstallOnceModuleTest$TestModule:            "misk.inject.KInstallOnceModuleTest$TestModule"
KInstallOnceModuleTest$TestValue:             "misk.inject.KInstallOnceModuleTest$TestValue"
MiskTestExtension$beforeEach$module$1:        "misk.testing.MiskTestExtension$beforeEach$module$1"
RealMapBinder:                                "com.google.inject.internal.RealMapBinder"
========================
End of classname legend:
========================