Skip to content

Commit 205d097

Browse files
committed
feature: running windows tests in session 1
1 parent 3d0e640 commit 205d097

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

lib/travis/worker/job/runner.rb

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,79 @@ def run_script
194194
exit $(cat ~/build.sh.exit)
195195
EOF
196196
session.exec("GUEST_API_URL=%s bash ~/wrapper.sh" % guest_api_url) { exit_exec? }
197+
elsif payload[:config][:os] == 'windows' && Hash === payload[:config][:windows] && payload[:config][:windows][:run_in_session1]
198+
session.upload_file("~/buildWrapper.sh", <<EOF % [Travis::Worker::VirtualMachine.config[:username], Travis::Worker::VirtualMachine.config[:password]])
199+
#!/bin/bash
200+
#curl -X POST -d '{"message":"Interactive runner started"}' $GUEST_API_URL/logs
201+
WIN_HOME_DIR=`cygpath -adw ~`
202+
PS1_FILE=`echo $WIN_HOME_DIR | sed s'|\\\\\\\\|\\\\\\\\\\\\\\\\|g'`\\\\runPSWrapper.ps1
203+
204+
/cygdrive/c/Tools/PsExec.exe -u "%s" -p "%s" -acceptEula -h -i 1 powershell -file "$PS1_FILE"
205+
206+
if [ -f ~/build.sh.exit ] ; then
207+
exit $(cat ~/build.sh.exit)
208+
else
209+
echo "Runner script was probably not executed, returning 1";
210+
exit 1;
211+
fi
212+
213+
EOF
214+
215+
session.upload_file("~/runPSWrapper.ps1", <<EOF % guest_api_url)
216+
$GUEST_API_URL="%s";
217+
[System.Reflection.Assembly]::LoadWithPartialName("System.Net");
218+
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions");
219+
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer;
220+
221+
$json = $ser.serialize(@{message= "`n`nMinttyRunner started`n`n"});
222+
$bytes = [System.Text.Encoding]::ASCII.GetBytes($json);
223+
$cl = new-object System.Net.WebClient;
224+
$cl.uploaddata("$GUEST_API_URL/logs", $bytes);
225+
226+
$p = new-object system.diagnostics.process;
227+
$p.StartInfo.UseShellExecute = $false;
228+
$p.StartInfo.CreateNoWindow = $true;
229+
$p.StartInfo.FileName = "c:\\cygwin\\bin\\mintty.exe";
230+
$p.StartInfo.Arguments = "-l - --exec /bin/bash -l -c 'exec /bin/bash ~/build.sh'";
231+
$p.StartInfo.RedirectStandardError = $p.StartInfo.RedirectStandardOutput = $true;
232+
233+
$block = {
234+
try
235+
{
236+
$hash = @{message = $event.SourceEventArgs.Data};
237+
$json = $ser.Serialize($hash);
238+
$cl = new-object System.Net.WebClient;
239+
$bytes = [System.Text.Encoding]::ASCII.GetBytes($json);
240+
$cl.uploaddata("$GUEST_API_URL/logs", $bytes);
241+
}
242+
catch
243+
{
244+
}
245+
}
246+
247+
Register-ObjectEvent -InputObject $p -EventName OutputDataReceived -Action $block -SourceIdentifier OutputReader | Out-Null;
248+
$p.Start() | out-null;
249+
$p.BeginOutputReadLine();
250+
while(-not $p.HasExited)
251+
{
252+
sleep 1;
253+
};
254+
if($p.StandardError -ne $null)
255+
{
256+
$p.StandardError.ReadToEnd()|Out-Host;
257+
};
258+
Unregister-Event -SourceIdentifier OutputReader;
259+
$p.WaitForExit();
260+
261+
$json = $ser.serialize(@{message= "`n`nMinttyRunner finished`n`n"});
262+
$bytes = [System.Text.Encoding]::ASCII.GetBytes($json);
263+
$cl = new-object System.Net.WebClient;
264+
$cl.uploaddata("$GUEST_API_URL/logs", $bytes);
265+
266+
exit $($p.ExitCode);
267+
268+
EOF
269+
session.exec("GUEST_API_URL=%s bash --login ~/buildWrapper.sh" % guest_api_url) { exit_exec? }
197270
else
198271
session.exec("GUEST_API_URL=%s bash --login ~/build.sh" % guest_api_url) { exit_exec? }
199272
end

lib/travis/worker/virtual_machine.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def self.provider
1616
self.const_get(provider_name)
1717
end
1818
end
19+
20+
def self.config
21+
provider_name = Travis::Worker.config.vms.provider
22+
Travis::Worker.config.send(provider_name.to_sym)
23+
end
1924
end
2025
end
2126
end

lib/travis/worker/virtual_machine/soap_provider.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def initialize(name)
3131

3232
def prepare
3333
info "soap API adapter prepared"
34+
@client = Savon.client(client_config)
3435
end
3536

3637
def sandboxed(opts = {})
@@ -121,18 +122,14 @@ def client_config
121122
res
122123
end
123124

124-
def client
125-
@client ||= Savon.client(client_config)
126-
end
127-
128125
def template_name(opts)
129126
if soap_config.image_override
130127
soap_config.image_override
131128
else
132129
raise "Could not construct templateName, dist field must not be empty" unless opts[:dist]
133130

134-
[ soap_config.template_name_prefix,
135-
opts[:dist],
131+
[ soap_config.template_name_prefix,
132+
opts[:dist],
136133
opts[:group]
137134
].select(&:present?).join('_')
138135
end

0 commit comments

Comments
 (0)