Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Testing a library that accesses an Oracle Database

by docdurdee (Scribe)
on Sep 22, 2016 at 03:21 UTC ( #1172337=perlquestion: print w/replies, xml ) Need Help??

docdurdee has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I'm writing tests for a program that accesses an Oracle database. When I run the tests directly or using prove, the tests work wonderfully. When I build the distribution (using Dist::Zilla) and run tests from the generated makefile, they fail: Could not connect to ... : install_driver(Oracle) failed: Can't load ... Library not loaded: @rpath/libclntsh.dylib.12.1 It must be an environment issue (I'm running OS X), but I have not been able to crack it via the usual endless googling. I think there may be some way to get the appropriate variables set via Dist::Zilla using the D::Z::P::MakeMaker::Awesome, but I shelved that effort in favor of hacking something that works at all to begin with. I tried setting the Oracle %ENV variables (dumped from my local environment where it works) within the problematic test using a BEGIN block, but still no luck...
BEGIN { $ENV{ORACLE_HOME}="somepathto/oracle"; $ENV{DYLD_LIBRARY_PATH}="somepathto/oracle/lib"; }
Any ideas? Thanks! UPDATE: I also tried unsetting the environment variables from within the test that works when I run it directly:
The test still works!!!! I'm only able to make the test crash during the "make test" phase. This is curious...

Replies are listed 'Best First'.
Re: Testing a library that accesses an Oracle Database
by kcott (Bishop) on Sep 22, 2016 at 05:53 UTC
      The DYLD_LIBRARY_PATH is OS X related. I tried setting LD_LIBRARY_PATH, but that doesn't work.

        Fair enough. I'm also using Mac OS X (10.10.3) but, as I don't have local access to Oracle, I'm unable to run any tests for you. Here's a few more thoughts and suggestions.

        Using backticks (as shown in your update) will not be helpful. The command within the backticks will be executed in a new process environment which will be discarded (and the old process environment restored) when completed. E.g.

        $ XXX=unset perl -E 'say "$$: XXX=$ENV{XXX}"; print `export XXX=xxx; e +cho \$\$: XXX=\$XXX`; say "$$: XXX=$ENV{XXX}"' 3494: XXX=unset 3495: XXX=xxx 3494: XXX=unset

        Also from your update, if setting $ENV{whatever} in a BEGIN block has no apparent effect, then that BEGIN block is possibly being reached too late. Try putting that BEGIN block earlier in the code. Remember, BEGIN blocks are executed in FIFO order, and use statements are

        ... exactly equivalent to

        BEGIN { require Module; Module->import( LIST ); }

        Consider writing env.t (or similar) with lines like:

        ok $ENV{whatever} eq $whatever_expected_value, ...

        Try setting environment values on the command line (like I did with XXX=unset above) prior to running your tests. I'm not suggesting this as a solution, but it may provide some useful feedback. You can set multiple values, e.g.

        DYLD_LIBRARY_PATH=... ORACLE_HOME=... make test

        Check if Dist::Zilla is performing actions based on what it considers to be tainted data (see perlsec). This could affect your environment.

        I'll also front-page this thread to try to get you a bit more coverage.

        — Ken

        Actually, either the LD_LIBRARY_PATH or DYLD_LIBRARY_PATH will work as long as they are actually set in the environment. Thanks! Following Corion's suggestion, I was able to get it to work with the restart parameter. See my response to Corion's comment for details.
Re: Testing a library that accesses an Oracle Database
by Random_Walk (Prior) on Sep 22, 2016 at 04:29 UTC

    Do you have the tnsname.ora file from the working systems replicated to the test systems or at least the section that enables Oracle to resolve the DB to which you connect? It should normally be in $ORACLE_HOME/network/admin/tnsnames.ora


    Pereant, qui ante nos nostra dixerunt!
Re: Testing a library that accesses an Oracle Database
by Corion (Pope) on Sep 22, 2016 at 19:21 UTC

    At least with some environment variables and some operating systems, the variables are only used by the OS at process start time. This means that setting the environment variables after the start of your process does not help the current instance of your process. One approach to circumvent is to set up the environment within the first instance of your process and then to relaunch the process via exec. See for some examples:

      Thanks Corion!! I was able to get it to work following your previous posts on the topic. Adding this to head of the test:
      BEGIN { if( ! $ENV{PDUPRE_RESTART}) { $ENV{LD_LIBRARY_PATH} = '...some Oracle path../lib'; #$ENV{DYLD_LIBRARY_PATH} = '...some Oracle path../lib'; #Either + LD OR DYLD works $ENV{PDUPRE_RESTART} = 1; exec $0, '--restarted', @ARGV }; };
      worked after I made the test an executable and set the shebang line to point to my local install of perl:
      I had it set to:
      !#/usr/bin/env perl
      but it didn't show up because I am in the habit of running my perl scripts/tests using `perl t/some.t`; if I run using `/usr/bin/env perl t/some.t` than I again get the error from the OP.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1172337]
Approved by GrandFather
Front-paged by kcott
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2021-05-17 04:45 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (154 votes). Check out past polls.