Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Issues with Windows #44

Open
Oceanswave opened this issue Oct 7, 2014 · 12 comments
Open

Issues with Windows #44

Oceanswave opened this issue Oct 7, 2014 · 12 comments
Labels

Comments

@Oceanswave
Copy link

Unfortunately, I'm seeing that seeing that SandCastle doesn't seem to execute scripts under windows.

var SandCastle = require('sandcastle').SandCastle;

var sandcastle = new SandCastle();

var script = sandcastle.createScript("\
  exports.main = function() {\
    exit('Hey ' + name + ' Hello World!');\
  }\
");

script.on('exit', function(err, output) {
    console.log(output); // Hello World!
});

script.on('timeout', function() {
    console.log('I timed out, oh what a silly script I am!');
});

script.run({name: 'Ben'});

results in a timeout

I timed out, oh what a silly script I am!

When using the Pool nothing seems to happen... no timeout, nothing.

var Pool = require('sandcastle').Pool;

var poolOfSandcastles = new Pool( { numberOfInstances: 3 }, { timeout: 6000 } );

var script = poolOfSandcastles.createScript("\
  exports.main = function() {\
    exit('Hello World!');\
  }\
");

script.on('exit', function(err, output) {
    console.log(output);
});

script.on('timeout', function(err, output) {
    console.log('I timed out, oh what a silly script I am!');
});

script.run({name: 'Ben'});
@seubert
Copy link

seubert commented Oct 8, 2014

I believe this is related to #41.

@Oceanswave
Copy link
Author

Making the changes in the referenced pull doesn't help any.

Seems like this never gets triggered..
this.sandbox.stdout.on('data', function(data) {
_this.waitingOnHeartbeat = false; // Used to keep only one heartbeat on the wire at a time.
_this.sandboxInitialized = true;
});

@bcoe
Copy link
Owner

bcoe commented Oct 9, 2014

I don't have a Windows VM up and running at the moment, the submission of a patch that gets tests running on Windows would gain my eternal gratitude :)

@jsas
Copy link
Contributor

jsas commented Nov 12, 2014

I'm finally getting to this. Windows doesn't like Unix sockets. @Oceanswave, I passed a free tcp port into the Sandcastle ops for "socket" and got it to work.

@bcoe
Copy link
Owner

bcoe commented Nov 12, 2014

@jsas that's awesome that a tcp connection did the trick, I wonder if we should make this the default approach; about to respond to your email.

@yoavprat
Copy link

@jsas , How do I open tcp ports in Windows?

@bcoe bcoe added the bug label Jun 10, 2016
@bcoe
Copy link
Owner

bcoe commented Jun 10, 2016

@shai067, @yoavapi adding you to this long-standing thread on Windows support.

Curious if anyone has had a chance to dig into this further?

@jsas
Copy link
Contributor

jsas commented Jun 10, 2016

Sorry folks, I stopped working with sandcastle a long time ago and also moved to osx.

@yoavprat
Copy link

@jsas I can understand why... It works beautifully on OSX / Linux

@marstein
Copy link

marstein commented Oct 4, 2016

In my team people did this to src/metadata/constraints/expressions.js:

import os from 'os';
import { Pool, SandCastle } from 'sandcastle';

function createPool() {
  /*
   * Horrendous hack to get sandcastle working on windows. This should only be important for running tests
   * locally on a windows machine - Lambda always runs on Linux so this code should never be executed in production.
   * SandCastle unfortunately assumes it can communicate with child processes via local sockets with names like
   * '/tmp/sandcastle_xx.sock' where xx is the instance number. But windows insists on names like '\\.\pipe\...'.
   * There's no way of configuring this in options to Pool creation so instead we hack the SandCastle prototype
   * to wrap the 'socket' property and transform it to a windows friendly format.
   */
  if (os.platform() === 'win32') {
    const socketPattern = /_(\d+)\./;
    console.log('Hacking socket property for Windows');
    Object.defineProperty(SandCastle.prototype, 'socket', {
      get: function () { // eslint-disable-line object-shorthand,func-names
        return this.realSocket;
      },
      set: function (value) { // eslint-disable-line object-shorthand,func-names
        let newValue = value;
        const found = value && value.match(socketPattern);
        if (found) {
          newValue = `\\\\.\\pipe\\sandcastle${found[1]}`;
        }
        this.realSocket = newValue;
      }
    });
  }
  return new Pool({ numberOfInstances: 3 }, { timeout: 6000 });
}

const sandcastle = createPool();

@yoavprat
Copy link

yoavprat commented Oct 4, 2016

@marstein - Thanks! we will give it a go.

@trevor-morris
Copy link

I added a pull request that attempts to fix things for Windows - #71

Works ok on my Windows 7 machine and on some co-workers' Macs. If anyone else wants to try it and make sure it runs ok (pull down the branch then run "npm install" and "npm run test") then feel free.

Unfortunately "npm install" can run into problems installing node-gyp on Windows. node-gyp generally seems somewhat problematic on Windows, depending on exactly what you've got installed. I got it working after Googling around a while, but another of my co-workers just tried "npm install" and got an entirely different error on their Windows box...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants