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

vweb: add an optional before_accept_loop/0 method, to make testing easier and more robust #20538

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

spytheman
Copy link
Member

@spytheman spytheman commented Jan 15, 2024

Allow for more robust testing using:

struct App {
	vweb.Context
mut:
	started chan bool
}

pub fn (mut app App) before_accept_loop() {
	app.started <- true
}

and later doing:

mut app := &App{}
spawn vweb.run(app, port)
_ := <-app.started

... without having to use polling or brittle time.sleep() calls.

See https://github.com/vlang/v/blob/43bc3069631a5b7b6433456d95cdae1326b4d1be/vlib/vweb/tests/vweb_should_listen_on_both_ipv4_and_ipv6_by_default_test.v

@enghitalo
Copy link
Contributor

enghitalo commented Jan 15, 2024

x.vweb will need/have something like that?

@spytheman
Copy link
Member Author

x.vweb will need/have something like that?

Probably yes, but that will be another PR.

@spytheman spytheman merged commit 6cfca66 into vlang:master Jan 15, 2024
42 checks passed
@spytheman spytheman deleted the vweb_add_before_accept_loop_method branch January 15, 2024 09:43
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.

None yet

2 participants