Bring out the big-paranoia-harness - make describe_env infallible
[dbsrgits/DBIx-Class.git] / t / 746mssql.t
index 2cc0281..d1b8773 100644 (file)
@@ -1,22 +1,19 @@
+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_mssql_odbc';
+
 use strict;
 use warnings;
 
 use Test::More;
 use Test::Exception;
+use Test::Warn;
 use Try::Tiny;
 
-use DBIx::Class::Optional::Dependencies ();
-plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mssql_odbc')
-  unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mssql_odbc');
 
-use lib qw(t/lib);
 use DBICTest;
 
 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
 
-plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this test'
-  unless ($dsn && $user);
-
 {
   my $srv_ver = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info->{dbms_version};
   ok ($srv_ver, 'Got a test server version on fresh schema: ' . ($srv_ver||'???') );
@@ -102,11 +99,35 @@ SQL
 
     ok(($new->artistid||0) > 0, "Auto-PK worked for $opts_name");
 
-# Test multiple active statements
-    SKIP: {
-      skip 'not a multiple active statements configuration', 1
-        if $opts_name eq 'plain';
+# Test graceful error handling if not supporting multiple active statements
+    if( $opts_name eq 'plain' ) {
+
+      # keep the first cursor alive (as long as $rs is alive)
+      my $rs = $schema->resultset("Artist");
+
+      my $a1 = $rs->next;
+
+      my $a2;
+
+      warnings_are {
+        # second cursor, invalidates $rs, but it doesn't
+        # matter as long as we do not try to use it
+        $a2 = $schema->resultset("Artist")->next;
+      } [], 'No warning on retry due to previous cursor invalidation';
+
+      is_deeply(
+        { $a1->get_columns },
+        { $a2->get_columns },
+        'Same data',
+      );
 
+      dies_ok {
+        $rs->next;
+      } 'Invalid cursor did not silently return garbage';
+    }
+
+# Test multiple active statements
+    else {
       $schema->storage->ensure_connected;
 
       lives_ok {
@@ -280,8 +301,8 @@ SQL
           my $sealed_owners = $owners->as_subselect_rs;
 
           is_deeply (
-            [ map { $_->name } ($sealed_owners->all) ],
-            [ map { $_->name } ($owners->all) ],
+            [ sort map { $_->name } ($sealed_owners->all) ],
+            [ sort map { $_->name } ($owners->all) ],
             "$test_type: Sort preserved from within a subquery",
           );
         }
@@ -331,20 +352,13 @@ SQL
           is ($limited_rs->count, 6, "$test_type: Correct count of limited right-sorted joined resultset");
           is ($limited_rs->count_rs->next, 6, "$test_type: Correct count_rs of limited right-sorted joined resultset");
 
-          my $queries;
-          my $orig_debug = $schema->storage->debug;
-          $schema->storage->debugcb(sub { $queries++; });
-          $schema->storage->debug(1);
-
-          is_deeply (
-            [map { $_->owner->name } ($limited_rs->all) ],
-            [@owner_names[2 .. 7]],
-            "$test_type: Prefetch-limited rows were properly ordered"
-          );
-          is ($queries, 1, "$test_type: Only one query with prefetch");
-
-          $schema->storage->debugcb(undef);
-          $schema->storage->debug($orig_debug);
+          $schema->is_executed_querycount( sub {
+            is_deeply (
+              [map { $_->owner->name } ($limited_rs->all) ],
+              [@owner_names[2 .. 7]],
+              "$test_type: Prefetch-limited rows were properly ordered"
+            );
+          }, 1, "$test_type: Only one query with prefetch" );
 
           is_deeply (
             [map { $_->name } ($limited_rs->search_related ('owner')->all) ],