V Testing gets stuck after starting server

50 views Asked by At

The computer I'm using is:

Distributor ID: Pop
Description: Pop!_OS 22.04 LTS
Release: 22.04
Codename: jammy

When I start up the server in tests it gets stuck with this banner:

---- Testing... ---------------------------------------------------------------------------

I'm trying to copy how this test is done in V for my own application.

So, an example application is:

In the file main.v.

module main

import vweb

struct App {
    vweb.Context
}

fn main() {
    mut app := &App{}
    vweb.run(app, 8000)
}

['/hi'; get]
fn (mut app App) get_greeting() vweb.Result {
    return app.text('Hello, George!')
}

And the test code is app_test.v:

module main

import os
import time

const (
    vexe = @VEXE
    serverexe = os.join_path(os.cache_dir(), 'server_tester.exe')
)

fn testsuite_begin() {
    if os.exists(serverexe) {
        os.rm(serverexe) or {}
    }
}

fn test_created_executable() {
    did_server_compile :=
        os.system('${os.quoted_path(vexe)} -o ${os.quoted_path(serverexe)} .')
    assert did_server_compile == 0
    assert os.exists(serverexe)
}

fn test_starts_server() {
    command := '${os.quoted_path(serverexe)} > /dev/null &'
    res := os.system(command) // ######## Test gets stuck here ########
    assert res == 0
    time.sleep(100 * time.millisecond)
}

fn test_fail() {
    assert 4 == 5
}

I'm expecting that the test_fail function should be reached and fail. But it is never reached.

When I run the code ~/.cache/server_tester.exe > /dev/null & that is run in the test it properly starts in the background. So, I'm not sure why it isn't starting properly in the background in the code.

The real life code that I'm writing where the test gets stuck.

0

There are 0 answers