Event handling within script modules

Not sure if this is a bug or I am using it wrong. Consider the following
snippet. I start it using `sudo ./bin/bro -i eth0 module_test`.

*File: share/bro/site/module_test/raise.bro*

module module_test;
# Remove the module to make the example work
# OR define the event handler within another module

export {
        global my_event: event(a: int, s: string);
}

event raise_my_event() {
        local a: int = 42;
        local s: string = "Hello World";
        print(fmt("Raising event with a=%d and s=%s", a, s));
        event my_event(a, s);
}

#module module2;

event my_event(a: int, s: string) {
        print(fmt("Received event with a=%d and s=%s", a, s));
}

event bro_init() {
        local w: interval = 10sec;
        print(fmt("Starting example, waiting for %s", w));
        #"raise_my_event()" is executed immediately
        schedule w {raise_my_event()};
}

# Problem 1: Event Handling within module
The handler for "my_event" is not invoked as long as it is defined
within the same module "module_test".
- Workaround a): Do not use modules at all
- Workaround b): Define the handler in a different module
But why should not it be allowed to raise and handle events within the
same module?

# Problem 2: Direct execution of scheduled events
At least within this example, I expected the "raise_my_event" to be
invoked after 10 seconds. However, it is done immediately. Am I using
the schedule wrong?

I am running the current master (0f550806252b46d3e13be24cd2ab4bb8a63bf49b).

Any help appreciated. Best,
Steffen.

# Problem 1: Event Handling within module
The handler for "my_event" is not invoked as long as it is defined
within the same module "module_test".
- Workaround a): Do not use modules at all
- Workaround b): Define the handler in a different module
But why should not it be allowed to raise and handle events within the
same module?

This is related to issues discussed at [1]. You can get the behavior
you want, but the short explanation/recommendation is to always use
the module prefix when raising/handling the event. So, in your
example, when you raise and handle the event, explicitly add
"module_test::" even when inside the module.

# Problem 2: Direct execution of scheduled events
At least within this example, I expected the "raise_my_event" to be
invoked after 10 seconds. However, it is done immediately. Am I using
the schedule wrong?

When there's no input sources (not listening on an interface) and
you're just running a script, timers may get processed as fast as
possible, but you can add this and you'll then see timers behave based
on wall clock:

    redef exit_only_after_terminate = T;

- Jon

[1] https://github.com/bro/bro/issues/163