Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

734 getting started tests #760

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/getting-started.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Getting Started steps

# This workflow is meant to emulate what developers working with the Agoric platform will experience
# It should be kept in sync with https://agoric.com/documentation/getting-started/

on:
push:
branches: [master]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Prerequisites

# FIXME: Reenable after 2020-04-01 when Github cache doesn't take forever.
#- name: cache Go modules
# uses: actions/cache@v1
# with:
# path: ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('packages/cosmic-swingset/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-

# 'yarn install' must be done at the top level, to build all the
# cross-package symlinks
- run: yarn install
- run: yarn build
- run: yarn link-cli ~/bin/agoric

- run: node test/gettingStarted.js


60 changes: 60 additions & 0 deletions test/agoric-deploy-ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const {exec, execSync} = require('child_process')

// To keep in sync with https://agoric.com/documentation/getting-started/

function runCommand(cmd, options={}){
try{
return execSync(cmd, {stdio: 'inherit', ...options})
}
catch(err){
console.error(`${cmd} error`, err)
process.exit(1)
}
}

console.log('cwd', process.cwd())

process.chdir('/tmp/demo')
console.log('cwd', process.cwd())



/*
With runCommand ({stdio: 'inherit'}), i can see the error in deploy
> cannot create initial offers TypeError: Cannot read property 'exit' of undefined


With exec below (stdout should be buffered and passed to the callback), but the string is empty. Same for stderr

No idea why there is a difference

*/

runCommand('agoric deploy ./contract/deploy.js ./api/deploy.js')

/*
exec('agoric deploy ./contract/deploy.js ./api/deploy.js', (err, stdout, stderr) => {
console.log('DEPLOY err', err)
console.log('DEPLOY stdout', typeof stdout)
console.log('DEPLOY stderr', typeof stderr)

process.exit()

process.chdir('ui')
console.log('cwd', process.cwd())

runCommand('yarn install')
runCommand('yarn start')
})*/




/*
cd demo
agoric deploy ./contract/deploy.js ./api/deploy.js
cd ui
yarn install
yarn start

*/
67 changes: 67 additions & 0 deletions test/agoric-init-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { request } = require('http')
const { spawn, execSync } = require('child_process')


// To keep in sync with https://agoric.com/documentation/getting-started/

function runCommand(cmd) {
console.log('RUNNING', cmd)
try {
execSync(cmd, { stdio: 'inherit' })
}
catch (err) {
console.error(`${cmd} error`, err)
process.exit(1)
}
}

console.log('cwd', process.cwd())

// cd /tmp
process.chdir('/tmp')
console.log('cwd', process.cwd())

runCommand('agoric init demo')

// cd demo
process.chdir('demo')
console.log('cwd', process.cwd())

runCommand('agoric install')

console.log('RUNNING', 'agoric start --reset')
const agoricStartProcess = spawn('agoric', ['start', '--reset'], { stdio: 'inherit' })
// for some reason, if stdout is piped, 'agoric start' closes the stream early, making it impossible to
// inspect stdout for relevant messages
// no other 'agoric x' command has this problem

// anyway, trying port 8000 until it does not return an error

const interval = setInterval(() => {
const sendReady = () => {
console.log('server on localhost:8000 is certainly ready')
if(process.send){
process.send({httpReady: true})
}
clearInterval(interval)
}

const noErrorTimeout = setTimeout(sendReady, 2000)

const req = request('http://localhost:8000/', res => {
console.log('something came back from localhost:8000')
sendReady()
clearTimeout(noErrorTimeout)
})

req.on('error', err => {
clearTimeout(noErrorTimeout)
if(err.code === 'ECONNREFUSED'){
console.error('agoric started server on localhost:8000 not ready yet')
}
else{
console.error('http 8000 error', err)
}
})

}, 3000)
76 changes: 76 additions & 0 deletions test/gettingStarted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { fork } = require('child_process');

const test = require('tape');

//const exec = promisify(execCb)

// to keep in sync with https://agoric.com/documentation/getting-started/


test('getting stated instructions', async t => {
console.log('Running commands in a first shell for agoric init + start')

const initStartProcessExitListener = code => {
console.error(`agoric init + start process stopped while it shouldn't have`)
t.fail(code);
t.end()
}
const deployUiProcessExitListener = code => {
console.log(`agoric deploy + ui stopped`)
process.exit()
t.end()
}

const initStartProcess = fork('./test/agoric-init-start.js', {stdio: 'inherit'})

initStartProcess.on('error', error => {
t.fail(error);
initStartProcess.kill()
t.end()
})
initStartProcess.on('exit', initStartProcessExitListener)

const vatsReadyP = new Promise(resolve => {
initStartProcess.on('message', (message) => {
console.log('receieved message from initStartProcess', message)
if(message.httpReady){
console.log('message.httpReady', message.httpReady)
resolve()
}
})
})


vatsReadyP
.then(() => {
console.log('In a second shell, run agoric deploy + ui + yarn install+start')

const deployUiProcess = fork('./test/agoric-deploy-ui.js', {stdio: 'inherit'})

deployUiProcess.on('error', error => {
t.fail(error);

initStartProcess.on('exit', initStartProcessExitListener)
initStartProcess.kill()

deployUiProcess.on('exit', deployUiProcessExitListener)
deployUiProcess.kill()

t.end()
})
deployUiProcess.on('exit', deployUiProcessExitListener)
})


// finalize steps
//t.pass('pass after 15secs')
//t.end()
//initStartProcess.off('exit', firstProcessExitListener)
//initStartProcess.kill()



//t.equal(mf1, 'getExport', 'module format is getExport');
//t.assert(src1.match(/require\('@agoric\/harden'\)/), 'harden is required');
//t.end();
});