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

4.49 Mojo::Test hangs up (Premature connection close) #560

Closed
unera opened this issue Nov 6, 2013 · 4 comments
Closed

4.49 Mojo::Test hangs up (Premature connection close) #560

unera opened this issue Nov 6, 2013 · 4 comments

Comments

@unera
Copy link

unera commented Nov 6, 2013

Hi, Today I've upgraded my test server from Mojo 3.91 to Mojo 4.49

Too many tests failed with 4.49 (Debian/unstable).

Failed all tests that check bridge-routes.

following example passes with 3.91 (and with Mojo 4.19) and hangs up with 4.49 (But if You start application - site will work fine).

test

#!/usr/bin/perl

use warnings;
use strict;
use utf8;
use open qw(:std :utf8);
use lib qw(lib ../lib);

use Test::More tests    => 12;
use Encode qw(decode encode);


BEGIN {
    my $builder = Test::More->builder;
    binmode $builder->output,         ":utf8";
    binmode $builder->failure_output, ":utf8";
    binmode $builder->todo_output,    ":utf8";

    use_ok 'Test::Mojo';
}



{
    package MyApp::Db;
    use Mojo::Base 'Mojolicious::Controller';
    sub check {
        return 1;
    }

    package MyApp::Cx;
    use Mojo::Base 'Mojolicious::Controller';
    sub ping {
        return $_[0]->render(text => 'pong');
    }

    package MyApp::User;
    use Mojo::Base 'Mojolicious::Controller';

    sub check {
        return 1;
    }

    sub check_fail {
        return 0;
    }

    sub default {
        return $_[0]->render(text => 'test');
    }

    sub list {
        return $_[0]->render(text => 'list');
    }

    sub ajax {
        return 1;
    }

    package MyApp;
    use Mojo::Base 'Mojolicious';

    sub startup {
        my ($self) = @_;
        for my $r ($self->routes->bridge->to('db#check')) {

            $r  -> get('/ping')
                -> to('cx#ping');

            for my $r ($r->bridge('/user/:uid/:hash')
                    ->to('user#check', layout => 'user', name => 'value') ) {
                $r  -> get('/')
                    -> to('user#default');


                for my $r ($r->bridge('/ajax')
                        ->to('user#ajax')) {
                    $r  -> get('/list')
                        -> to('user#list');


                    for my $r ($r->bridge('/fail')->to('user#check_fail')) {
                        $r  -> get('/')
                            -> to('user#default');
                    }
                }

                $r  ->get('/test')
                    ->to('user#test');
            }

        }
    }
}

my $t = Test::Mojo->new('MyApp');
$t  -> get_ok('/ping')
    -> status_is(200)
    -> content_is('pong')
;

$t  -> get_ok('/user/123/1234')
    -> status_is(200)
    -> content_is('test')
;

$t  -> get_ok('/user/123/1234/ajax/list')
    -> status_is(200)
    -> content_is('list')
;

$t  -> get_ok('/user/123/1234/ajax/fail')
    -> status_is(404)
;

Mojo 3.91

1..12
ok 1 - use Test::Mojo;
ok 2 - get /ping
ok 3 - 200 OK
ok 4 - exact match for content
ok 5 - get /user/123/1234
ok 6 - 200 OK
ok 7 - exact match for content
ok 8 - get /user/123/1234/ajax/list
ok 9 - 200 OK
ok 10 - exact match for content
ok 11 - get /user/123/1234/ajax/fail
ok 12 - 404 Not Found

Mojo 4

1..12
ok 1 - use Test::Mojo;
ok 2 - GET /ping
ok 3 - 200 OK
ok 4 - exact match for content
ok 5 - GET /user/123/1234
ok 6 - 200 OK
ok 7 - exact match for content
ok 8 - GET /user/123/1234/ajax/list
ok 9 - 200 OK
ok 10 - exact match for content
# Premature connection close
not ok 11 - GET /user/123/1234/ajax/fail
#   Failed test 'GET /user/123/1234/ajax/fail'
#   at mojo.t line 113.
not ok 12 - 404 Not Found
#   Failed test '404 Not Found'
#   at mojo.t line 113.
#          got: undef
#     expected: '404'
# Looks like you failed 2 tests of 12.
@unera
Copy link
Author

unera commented Nov 6, 2013

4.54 hangs up, too

@Tekki
Copy link

Tekki commented Nov 6, 2013

sub check_fail {
  shift->render_not_found;
  return 0;
}

You should ask support questions in the forum https://groups.google.com/forum/#!forum/mojolicious

@kraih
Copy link
Member

kraih commented Nov 6, 2013

And @Tekki is correct, i'm afraid this is not a bug. http://mojolicio.us/perldoc/Mojolicious/Guides/Contributing#SUPPORT

@kraih kraih closed this as completed Nov 6, 2013
@amenonsen
Copy link
Contributor

At 2013-11-06 11:15:14 -0800, notifications@github.com wrote:

If You will use return $_[0]->render_not_found;, route controller
will be called in any case.

You are right. The workaround does not work in bridge functions.

Instead, you should use:

sub check_fail {
    $_[0]->render_not_found;
    return 0;
}

…or something like that. I usually use:

$self->render(text => "Permission denied", status => 403);

in this situation.

But I agree that there is no bug here.

-- ams

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

4 participants