Index: /branches/eam_branches/ipp-20191011/Nebulous-Server/t/08_server_find_instances.t
===================================================================
--- /branches/eam_branches/ipp-20191011/Nebulous-Server/t/08_server_find_instances.t	(revision 40981)
+++ /branches/eam_branches/ipp-20191011/Nebulous-Server/t/08_server_find_instances.t	(revision 40982)
@@ -8,5 +8,5 @@
 use warnings FATAL => qw( all );
 
-use Test::More tests => 19;
+use Test::More tests => 25;
 
 use lib qw( ./t ./lib );
@@ -22,6 +22,17 @@
 );
 
-Test::Nebulous->setup;
-
+# object exists but instance is on a different volume
+# "~node02" is meant to be a hard volume
+
+# XXX previously, the logic was: if we request a hard volume location
+# using ~node, then we would give an error if no data is available except on that node.
+
+# the code has been modified so that the requested storage object is provided if possible, 
+# even if the apparently "hard" target did not exist.
+
+Test::Nebulous->setup;
+Test::Nebulous->cleanup; # make sure the database is reset before running any tests
+
+Test::Nebulous->setup;
 {
     # key
@@ -35,5 +46,4 @@
 
 Test::Nebulous->setup;
-
 {
     # key
@@ -49,5 +59,4 @@
 
 Test::Nebulous->setup;
-
 {
     # key, volume
@@ -61,5 +70,4 @@
 
 Test::Nebulous->setup;
-
 {
     # key, volume
@@ -73,5 +81,4 @@
 
 Test::Nebulous->setup;
-
 {
     # key, volume
@@ -85,5 +92,4 @@
 
 Test::Nebulous->setup;
-
 {
     # key
@@ -100,12 +106,111 @@
 # object exists but instance is on a different volume
 Test::Nebulous->setup;
-
 eval {
     # key, volume
     my $uri = $neb->create_object('foo', '~node01');
-
     my $locations = $neb->find_instances('foo', '~node02');
-};
-like($@, qr/no instances on storage volume/, 'instances on a different volume');
+
+    uri_scheme_ok($locations->[0], 'file');
+    is($uri, $locations->[0], "URIs match");
+
+    # print "uri: $uri\n";
+    # print "result: $locations->[0]\n";
+};
+# die "quick check";
+# print "answer: $_[0]\n";
+# like($@, qr/no instances on storage volume/, 'instances on a different volume');
+
+# request from a soft_volume for an instance which is on an invalid node (find_invalid = 1) 
+# XXX should return the INVALID instance (currently 2019.10.24 does not)
+Test::Nebulous->setup;
+eval {
+    # key, volume
+    my $uri = $neb->create_object('foo', '~node02');
+    Test::Nebulous->switch_node_state;
+
+    my $locations = $neb->find_instances('foo', 'node02', 1);
+    uri_scheme_ok($locations->[0], 'file');
+    is($uri, $locations->[0], "URIs match");
+};
+is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid is set");
+#like($@, qr/database error/, "instance on invalid node (as hard_volume) not returned");
+
+# request from a soft_volume for an instance which is on an invalid node (find_invalid = 0) 
+# XXX should return the INVALID instance (currently 2019.10.24 does not)
+Test::Nebulous->setup;
+eval {
+    # key, volume
+    my $uri = $neb->create_object('foo', '~node02');
+    Test::Nebulous->switch_node_state;
+
+    my $locations = $neb->find_instances('foo', 'node02', 0);
+};
+#is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid is set");
+like($@, qr/database error/, "instance on invalid node (as soft_volume) not returned");
+
+#### tests with a hard_volume:
+
+# request from a hard_volume for an instance which is on an invalid node (find_instance not supplied)
+Test::Nebulous->setup;
+eval {
+    # key, volume
+    my $uri = $neb->create_object('foo', '~node02');
+    Test::Nebulous->switch_node_state;
+
+    my $locations = $neb->find_instances('foo', '~node02');
+};
+like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned");
+
+# request from a hard_volume for an instance which is on an invalid node (find_invalid = 1) 
+Test::Nebulous->setup;
+eval {
+    # key, volume
+    my $uri = $neb->create_object('foo', '~node02');
+    Test::Nebulous->switch_node_state;
+
+    my $locations = $neb->find_instances('foo', '~node02', 1);
+    uri_scheme_ok($locations->[0], 'file');
+    is($uri, $locations->[0], "URIs match");
+};
+is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid is set");
+#like($@, qr/database error/, "instance on invalid node (as hard_volume) not returned");
+
+# request from a hard_volume for an instance which is on an invalid node (find_invalid = 0)
+Test::Nebulous->setup;
+eval {
+    # key, volume
+    my $uri = $neb->create_object('foo', '~node02');
+    Test::Nebulous->switch_node_state;
+
+    my $locations = $neb->find_instances('foo', '~node02', 0);
+};
+like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned");
+
+# request from a hard_volume for an instance which is on an invalid node 
+Test::Nebulous->setup;
+eval {
+    # key, volume
+    my $uri = $neb->create_object('foo', '~node02');
+    Test::Nebulous->switch_node_state;
+
+    my $locations = $neb->find_instances('foo', '~node02', 1);
+
+    uri_scheme_ok($locations->[0], 'file');
+    is($uri, $locations->[0], "URIs match");
+};
+
+# request from a hard_volume returns an instance which is not on the hard volume if available
+Test::Nebulous->setup;
+eval {
+    # key, volume
+    my $uri = $neb->create_object('foo', '~node01');
+
+    my $locations = $neb->find_instances('foo', '~node02');
+
+    uri_scheme_ok($locations->[0], 'file');
+    is($uri, $locations->[0], "URIs match");
+};
+
+########
 
 Test::Nebulous->setup;
@@ -125,9 +230,9 @@
 
 Test::Nebulous->setup;
-
-eval {
-    $neb->find_instances();
-};
-like($@, qr/1 - 2 were expected/, "no params");
+eval {
+    my $locations = $neb->find_instances();
+};
+like($@, qr/1 - 3 were expected/, "no params");
+# note the new API expects 1-3 parameters
 
 Test::Nebulous->setup;
@@ -135,7 +240,8 @@
 eval {
     $neb->create_object('foo');
-    $neb->find_instances('foo', 'node01', 3);
-};
-like($@, qr/1 - 2 were expected/, "too many params");
+    $neb->find_instances('foo', 'node01', 3, 5);
+};
+like($@, qr/1 - 3 were expected/, "too many params");
+# note the new API expects 1-3 parameters
 
 Test::Nebulous->cleanup;
