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

Change ConfigFile to load after server init #3731

Closed
wants to merge 8 commits into from

Conversation

tarek-y-ismail
Copy link
Contributor

@tarek-y-ismail tarek-y-ismail commented Jan 30, 2025

Should allow initial config reads to interact with server components properly.

Also, tweaked tests a bit to be more explicit about failures. More importantly, tests now start the server manually to allow each test's ConfigFile instance to be set up. This brings the test behavior closer to the real use case in server_example.cpp

@tarek-y-ismail tarek-y-ismail self-assigned this Jan 30, 2025
@tarek-y-ismail tarek-y-ismail marked this pull request as ready for review January 30, 2025 12:02
@tarek-y-ismail tarek-y-ismail requested a review from a team as a code owner January 30, 2025 12:02
Copy link
Collaborator

@AlanGriffiths AlanGriffiths left a comment

Choose a reason for hiding this comment

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

This isn't working:

./miral-test --gtest_filter=TestConfigFile.with_reload_on_change_a_file_in_xdg_config_home_is_reloaded --gtest_repeat=10

Will show around 50% failures

(The patch I shared on MM doesn't do any better)

tests/miral/config_file.cpp Outdated Show resolved Hide resolved
tests/miral/config_file.cpp Outdated Show resolved Hide resolved
@tarek-y-ismail tarek-y-ismail force-pushed the config-file-load-after-server-init branch from 4b3efd5 to f6f04ce Compare January 30, 2025 15:07
tarek-y-ismail and others added 4 commits January 30, 2025 17:09
Most cases should fail if a load doesn't happen during the timeout
window, but some others should pass if the testcase expects the load to
not occur.
Should fix tests crashing due to the test running on one thread and the
server on another

Co-authored-by: Alan Griffiths <[email protected]>
@tarek-y-ismail tarek-y-ismail force-pushed the config-file-load-after-server-init branch from f6f04ce to 6a0f1b9 Compare January 30, 2025 15:10
@tarek-y-ismail
Copy link
Contributor Author

Will show around 50% failures

Replacing std::cerr with FAIL() in wait_for_load shows that this also happens on main. Though it seems more frequent with the changes in this PR. Increasing the timeout up to 10 seconds doesn't help so the issue must be deeper

Copy link
Contributor

@hbatagelo hbatagelo left a comment

Choose a reason for hiding this comment

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

It all seems reasonable to me, and the tests pass consistently when run locally. However, lxd::ubuntu-24.04:spread/build/ubuntu:ubsan is failing with init_and_start() timed out. Maybe increase the timeout?

@AlanGriffiths
Copy link
Collaborator

I now have to wonder: is this actually what we want to do?

Before this we were loading a config file immediately and the problem was that we wanted to apply it to objects that don't exist at that time.

But another scenario is to want to use configuration values in initialising the program. For that the current behaviour of loading the file immediately is the better timing.

Instead of deferring loading the configuration as proposed here, it would be possible, and more flexible, to defer applying the configuration.

@tarek-y-ismail
Copy link
Contributor Author

So here's what i think we can do, in addition to the existing on_load lambda. We can pass another delayed_apply lambda that the user can call at whatever point they want. If the use wants to load and apply the settings at the same time, the can forego the extra lambda. What do you think?

@AlanGriffiths
Copy link
Collaborator

So here's what i think we can do, in addition to the existing on_load lambda. We can pass another delayed_apply lambda that the user can call at whatever point they want. If the use wants to load and apply the settings at the same time, the can forego the extra lambda. What do you think?

I think the user can do all that without bothering ConfigFile: they take the data provided by on_load and store it for later use.

For example, in miral::InputConfiguration::Self::apply() the if statement:

        if (auto const idh = input_device_hub.lock())
        {
            idh->for_each_mutable_input_device([&m](auto& input_device)
            {
                m.self->apply_to(input_device);
            });
        }

Currently there is no else branch, but that could store the value for use by the init_ callback.

@tarek-y-ismail
Copy link
Contributor Author

tarek-y-ismail commented Jan 31, 2025

I don't even think we need to fiddle with InputConfiguration. Something like:

miral::InputConfiguration input_configuration;
    
// Share mouse/touchpad/keyboard settings between initial load and reloads
auto mouse = input_configuration.mouse();
auto touchpad = input_configuration.touchpad();
auto keyboard = input_configuration.keyboard();

// Load and try to apply settings immediately, repeat whenever the file changes.
miral::ConfigFile test{runner, "mir_demo_server.input", miral::ConfigFile::Mode::reload_on_change,
	[&](auto& in, auto path) 
	{
	    // Existing config loading/parsing code

            // Apply settings
            input_configuration.mouse(mouse);
            input_configuration.touchpad(touchpad);
            input_configuration.keyboard(keyboard);
	}
}};

// Apply settings on compositor startup
runner.add_start_callback(
[&]
{
    input_configuration.mouse(mouse);
    input_configuration.touchpad(touchpad);
    input_configuration.keyboard(keyboard);
});

Seems to do the trick. There's a little duplication but I'm okay with that, what do you think? If you're okay with doing things this way, feel free to close this PR (sorry Harlen :))

@AlanGriffiths
Copy link
Collaborator

There's a little duplication but I'm okay with that

Well, the duplication does reflect shared requirement, rather than shared implementation. Maybe extract an apply_input_settings() function?

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

Successfully merging this pull request may close these issues.

4 participants