SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PROBLEMS CREATING AN SSH TUNNEL

    Hello,
    I'm writing a series of test that test credit cart transactions and our card service relies on communicating to a sabrix server through an ssh tunnel.
    I've created something that works but I have to admit, it doesn't make sense because I'm using a combination of a unix exec call and Net::SSH::Gateway.
    In order for the ssh tunnel work with the tests to to work they HAVE to work in conjunction to each other. I'm ok with it but it seems like 1 out of 10 times, the tests will fail because the ssh tunnel isn't open for some reason. I've tried about every solution out there but can't seem to get anything else to work. Here's the code:

    Code:
      def setup
        super
        @controller = AccountController.new    
        @pid = fork{ exec("ssh -N -L 8888:10.0.1.68:8080 test@test.test.com") } #this has to be open in a thread
        @gateway = Net::SSH::Gateway.new('test.test.com', 'deploy')             #this has to be created as well
        sleep(1) #sleep just a tad to let everything start up
      end
    
      def test_update_credit_card_info
        #test code here…
      end
    And in my teardown method, I'm killing the ssh tunnel like this:

    Code:
      def teardown
        system("kill -9 #{@pid}") #kill by pid
        @gateway.shutdown!	#kill the Net::SSH::Gateway instance
      end
    Any ideas?

    Thanks,
    Eric

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,116
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Hi Eric,

    I'm not going to be much help here as I haven't dealt with code like this before, I believe most people would mock the gateway object so that you're only testing the code / validations you've written. The Net::SSH::Gateway object will behave as expected so you only need to test your code around it.

    https://github.com/rspec/rspec-mocks

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    London
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try logging the output of your ssh exec.
    my guess is the port is still busy. how long are you waiting between setups?

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markbrown4 View Post
    Hi Eric,

    I'm not going to be much help here as I haven't dealt with code like this before, I believe most people would mock the gateway object so that you're only testing the code / validations you've written. The Net::SSH::Gateway object will behave as expected so you only need to test your code around it.

    https://github.com/rspec/rspec-mocks
    Hey - there thanks for getting back to me on this and sorry for the long reply. I've been out sick in the last few days.

    I do not want to deal with mocking an ssh tunnel because I want the test to be 100% a real test. I want to make sure the communication between my code and the server to be 100% real. I want to be able to detect any changes that come back from the sabrix server transactions.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey jurn,
    It seems like just a simple sleep(1) at end of the teardown is doing the trick. More testing needed and I'll report back.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •