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

placement of use statement #5789

Open
p6rt opened this issue Nov 8, 2016 · 9 comments
Open

placement of use statement #5789

p6rt opened this issue Nov 8, 2016 · 9 comments

Comments

@p6rt
Copy link

p6rt commented Nov 8, 2016

Migrated from rt.perl.org#130050 (status was 'open')

Searchable as RT130050$

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @MARTIMM

Hi,

in rakudo 2016.10-249-gb84158c built on MoarVM version
2016.10-37-gf769569 implementing Perl 6.c, I've seen the following problem.

When a use statement was placed as the first one, the class was not
recognized and I got the following error(in this case MongoDB​::Client
which is loaded with 'use MongoDB​::Client')​:

===SORRY!=== Error while compiling
/home/marcel/Languages/Perl6/Projects/mongo-perl6-driver/t/Test-support.pm6
(Test-support)
Type 'MongoDB​::Client' is not declared
at
/home/marcel/Languages/Perl6/Projects/mongo-perl6-driver/t/Test-support.pm6
(Test-support)​:119
------> n ( Int :$server = 1 --> MongoDB​::Client⏏ ) {

When I move the statement one line below another use statement the error
still comes back. Only when the line is below all other use statements
the error disappears as if the other use statements cancels out the the
MongoDB​::Client definition.

This is a situation which I've not seen anywhere else and I do not know
if there is something wrong in the code or not, Maybe it has something
to do with the recent changes in lexical module loading.

Anyways, the statement is placed somewhere else and the project can
continue.

Regards,
Marcel

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @coke

On Tue, 08 Nov 2016 04​:42​:32 -0800, mt1957@​gmail.com wrote​:

Hi,

in rakudo 2016.10-249-gb84158c built on MoarVM version
2016.10-37-gf769569 implementing Perl 6.c, I've seen the following problem.

When a use statement was placed as the first one, the class was not
recognized and I got the following error(in this case MongoDB​::Client
which is loaded with 'use MongoDB​::Client')​:

===SORRY!=== Error while compiling
/home/marcel/Languages/Perl6/Projects/mongo-perl6-driver/t/Test-support.pm6
(Test-support)
Type 'MongoDB​::Client' is not declared
at
/home/marcel/Languages/Perl6/Projects/mongo-perl6-driver/t/Test-support.pm6
(Test-support)​:119
------> n ( Int :$server = 1 --> MongoDB​::Client⏏ ) {

When I move the statement one line below another use statement the error
still comes back. Only when the line is below all other use statements
the error disappears as if the other use statements cancels out the the
MongoDB​::Client definition.

This is a situation which I've not seen anywhere else and I do not know
if there is something wrong in the code or not, Maybe it has something
to do with the recent changes in lexical module loading.

Anyways, the statement is placed somewhere else and the project can
continue.

Regards,
Marcel

Can you provide a code sample showing the issue?

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @MARTIMM

Hi Will,

It is the MongoDB distribution in the file t/Test-support.pm6. It starts
with;

use v6.c;

use MongoDB​::Client;
use MongoDB​::Collection;
use MongoDB​::Server​::Control;

and throws an error at line 119;

119​: method get-connection ( Int :$server = 1 --> MongoDB​::Client ) {
  $server = 1 unless $server ~~ any $!server-range;
  my Int $port-number = $!server-control.get-port-number("s$server");
MongoDB​::Client.new(​:uri("mongodb​://localhost​:$port-number"));
  }

Changing the top into;

use v6.c;

use MongoDB​::Collection;
use MongoDB​::Server​::Control;
use MongoDB​::Client;

clears the error. There are many modules involved so it is difficult to
golf it to a simpler form. The code can be found at
https://github.com/MARTIMM/mongo-perl6-driver. You have to look into the
'develop' branch for the files. The problem file(Test-support) is in the
attachment together with the 3 modules and the test file using the
Test-support.

Regards,
Marcel

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @MARTIMM

Test-support.pm6

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @MARTIMM

Client.pm6

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @MARTIMM

Collection.pm6

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @MARTIMM

Control.pm6

@p6rt
Copy link
Author

p6rt commented Nov 8, 2016

From @MARTIMM

use v6.c;
use lib 't';

use Test;
use Test-support;
use MongoDB;
use MongoDB​::Client;
use MongoDB​::Server;

#-------------------------------------------------------------------------------
#set-logfile($*OUT);
#set-exception-process-level(MongoDB​::Severity​::Trace);
info-message("Test $?FILE start");

my MongoDB​::Test-support $ts .= new;

my Int $p1 = $ts.server-control.get-port-number('s1');
my Int $p2 = $ts.server-control.get-port-number('s2');
my MongoDB​::Client $client;
my MongoDB​::Server $server;

#-------------------------------------------------------------------------------
subtest {

  my Str $server-name = 'non-existent-server.with-unknown.domain​:65535';
  $client .= new(​:uri("mongodb​://$server-name"));
  isa-ok $client, MongoDB​::Client;

  $server = $client.select-server(​:3check-cycles);
  nok $server.defined, 'No servers selected';
# is $client.nbr-servers, 1, 'One server object set';
  is $client.server-status($server-name), C-NON-EXISTENT-SERVER,
  "Status of server is $client.server-status($server-name)";

  $client.cleanup;
}, 'Non existent server';
#done-testing();
#exit(0);

#-------------------------------------------------------------------------------
subtest {

  $client .= new(​:uri("mongodb​://localhost​:65535"));
  $server = $client.select-server(​:2check-cycles);
  nok $server.defined, 'No servers selected';
# is $client.nbr-servers, 1, 'One server object set';
  is $client.server-status('localhost​:65535'), C-DOWN-SERVER,
  "Status of server is $client.server-status('localhost​:65535')";

  $client.cleanup;
}, 'Down server';

#-------------------------------------------------------------------------------
subtest {

  $client .= new(​:uri("mongodb​://​:$p1"));
  $server = $client.select-server;

# todo 'Seems to finish processing too soon', 2;
# is $client.nbr-servers, 1, 'One server found';
  is $client.server-status("localhost​:$p1"), C-MASTER-SERVER,
  "Status of server is $client.server-status("localhost​:$p1")";

  $client.cleanup;
}, "Standalone server";

#-------------------------------------------------------------------------------
subtest {

  $client .= new(​:uri("mongodb​://​:$p1,​:$p2"));
  $server = $client.select-server;
  is $server.get-status, C-MASTER-SERVER,
  "Server $server.name() is $server.get-status()";

  # If server has port from $p1 than the other must have status rejected
  my $other-server = $client.select-server(​:needed-state(C-REJECTED-SERVER));
  is $client.server-status( $other-server.name), C-REJECTED-SERVER,
  "Server $other-server.name() is $client.server-status($other-server.name)";

# is $client.nbr-servers, 2, 'Two servers found';

  $client.cleanup;
}, "Two equal standalone servers";

#-------------------------------------------------------------------------------
# Cleanup
#
info-message("Test $?FILE end");
done-testing();
exit(0);

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

1 participant