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

Mock providers don't seem to be loaded on an non-RPi system #368

Closed
FDelporte opened this issue Jul 26, 2024 · 6 comments
Closed

Mock providers don't seem to be loaded on an non-RPi system #368

FDelporte opened this issue Jul 26, 2024 · 6 comments
Assignees

Comments

@FDelporte
Copy link
Member

FDelporte commented Jul 26, 2024

Related to Pi4J/pi4j-kotlin#12

When initializing a new context on a non-RPi system, it seems the mock plugin is not loaded. Could this be related to the new priority system for plugins, which was introduced recently?

Fix in code is available like this, as used e.g. in unit tests: https://github.com/Pi4J/pi4j-kotlin/blob/master/lib/src/test/kotlin/com/pi4j/ktx/ContextTest.kt

    @BeforeTest
    fun setup() {
        context = Pi4J.newContextBuilder()
            .add(MockPwmProvider.newInstance())
            .build();
    }

I think with the right approach, we could prevent the need to manually add the mock for testing on non-RPi-systems, so this code in the Spring Boot Starter would become unnecessary: https://github.com/Pi4J/pi4j-springboot/blob/main/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java#L31

@taartspi
Copy link
Collaborator

taartspi commented Aug 4, 2024

@FDelporte
I believe the change was prior to the 'provider priorities" change.
770a0f6
Implements the possible context creation of: pi4j = Pi4J.newAutoContextAllowMocks(); The result was [/DefaultRuntime.java] when a Mock provider is being evaluated for inclusion the config.autoDetectMockPlugins() is checked.

I see the Core tests cases now use this new means to create the context. So that is what I think happened, you asked what we should do.

  1. document this fact. ( I didn't look to see what the WEB might already say) . But I imagine we cansay more
  2. When we determine the Board info, if not a Pi, load the Mocks under the covers

Since @eitch added a specific means to load the Mocks I want his opinion. I think under the covers is not the way as one, I dislike magic happening unknown to me, and two, what about other providers that may successfully load whether ours or some user implemented providers. Should they be permitted ? Seems a slippery slope.

@eitch
Copy link
Member

eitch commented Aug 5, 2024

I think this can be solved by changing this line: com/pi4j/context/impl/DefaultContextBuilder.java:54 from:

protected boolean autoDetectMockPlugins = false;

to

protected boolean autoDetectMockPlugins = !BoardInfoHelper.runningOnRaspberryPi();

What do you think?

@eitch
Copy link
Member

eitch commented Aug 5, 2024

See #373

@taartspi
Copy link
Collaborator

taartspi commented Aug 5, 2024

I think that is a good solution. Let me know if u want me to assist in further web doc reviews for this work. As it does change behavior you earlier asked about new releases or a point for the ongoing changes. I think this change is a new release (i see u have referred to next release in some items so that seems the plan)

@eitch
Copy link
Member

eitch commented Sep 17, 2024

This has now been implemented in #373. Now mocks are loaded on non-rpi systems automatically, but not loaded on the Raspi. The documentation should probably document, that to load mocks on the Raspi, we need to use the following line:

Pi4J.newContextBuilder().autoDetectMockPlugins().build();

@eitch eitch closed this as completed Sep 17, 2024
@FDelporte
Copy link
Member Author

will add to release notes and documentation with next version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants