var net;
var Net;
describe('Net', function () {
    it('require', function () {
        net = require('../../lib/common/Net.js');
    });
    // it("asyncReapeat", function () {
    //     var net = require('../../lib/common/Net.js');
    //     var fakecallback = jasmine.createSpy("fake fun").andCallFake(function ()
    //         {
    //             return true;
    //         }
    //         );
    //     var callback = function (call, don) {
    //         return true;
    //     }
    //     net.asyncRepeat(fakecallback,true);
    //     expect(fakecallback).toHaveBeenCalled();
    // });
    it("findFreePort", function () {
        var Net = require('net');
        var ret = { 
            on: function (string, fun, err) {
                fun();
            },
            destroy: function () {}
        };
        spyOn(Net, 'createConnection').andReturn(ret);
        var net = require('../../lib/common/Net.js');
        var port = null;
        var err = null;
        net.findFreePort(1, 10, "test", function(merr, mport) {
            port = mport;
            err = merr;
        });
        expect(err).toBeUndefined();
        expect(port).not.toBeNull();
    });
    it("getPidByPort", function () {
        var child_process = require("child_process");
        var port = 888;
        var pid = 1000;
        spyOn(child_process, "exec").andCallFake(function (cmd, callback)
            {
                var stdout = ":" + port + "   LISTEN    " + pid;
                callback(null, stdout, null);
            }
            );
        var ret_pid = 0;
        var net = require('../../lib/common/Net.js');
        net.getPidByPort(port, function(err, pid) {
            ret_pid = pid;
        });
        expect(ret_pid).toEqual(pid);
    
    });
});
