Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
Async.parallelLimit Function Executing Callback Function Before Tasks

I am attempting to setup some newman test runs in parallel for different environments, and then create a Jira ticket via API request once all are completed with the results. However, when I use the ansync.parallelLimit function for that task, I find that the jira ticket gets created without any of the information from the test runs.

A simplified version of the process is this:

var async = require('async');
const path = require('path');
const newman = require('newman');
config = require(path.join(__dirname, 'config.json'));

const jira_data = [];

var create_ticket = function(err, results){
    console.log("Run Complete");
};

var test_run = async() =>{
  newman.run({
    collection: path.join(__dirname, 'Test.postman_collection.json'),
    reporters: ['htmlextra'],
    reporter: {
      htmlextra : { export : path.join(__dirname, '/reports/Test.html')}
    },})
}

var commands = [test_run,test_run,test_run,test_run];

async.parallelLimit(commands,4, (err, results) => {
  console.log("Run Complete");
  console.log(results);
});

That will result in the following output, indicating create_ticket was executed before anything else:

Run Complete
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.

Alternatively, I can make test_run a function instead of async, like this:

var async = require('async');
const path = require('path');
const newman = require('newman');

const jira_data = [];

var create_ticket = function(err, results){
    console.log("Test Run Complete");
};

var test_run = function() {
  newman.run({
    collection: path.join(__dirname, 'Test.postman_collection.json'),
    reporters: ['htmlextra'],
    reporter: {
      htmlextra : { export : path.join(__dirname, '/reports/Test.html')}
    },}).on('request', function(err, results) {
      console.log("Hello");
    })
}

var commands = [test_run, test_run, test_run, test_run];

async.parallelLimit(commands, 4, create_ticket);

But now, create ticket doesn't run at all:

Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Using htmlextra version 1.22.3
Hello
Hello
Hello
Hello
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.
Created the htmlextra report.

After spending more time than I care to admit playing with different combinations of variable types, argument passing, and other fixes, I am completely stumped. Any help at all would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to pass and call a callback into test_run to complete the asynchronous task.

var test_run = function(callback) {
  newman.run({
    collection: path.join(__dirname, 'Test.postman_collection.json'),
    reporters: ['htmlextra'],
    reporter: {
      htmlextra : { export : path.join(__dirname, '/reports/Test.html')}
    },}).on('request', function(err, results) {
      console.log("Hello");
      callback(null);
    })
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda