7 declare(strict_types=1);
20 private $consumers = [];
35 private $maxMessages =
null;
45 private $appInitParams;
61 $this->consumers = $consumers;
62 $this->publisher = $publisher;
63 $this->logFilePath = $logFilePath;
64 $this->maxMessages = $maxMessages;
65 $this->osInfo = $osInfo;
66 $this->appInitParams = $appInitParams;
67 $this->amqpHelper = $amqpHelper;
78 if ($this->osInfo->isWindows()) {
80 "This test relies on *nix shell and should be skipped in Windows environment." 83 $connections = $this->amqpHelper->getConnections();
84 foreach (array_keys($connections) as $connectionName) {
85 $this->amqpHelper->deleteConnection($connectionName);
87 $this->amqpHelper->clearQueue(
"async.operations.all");
88 foreach ($this->consumers as $consumer) {
89 foreach ($this->getConsumerProcessIds($consumer) as $consumerProcessId) {
90 exec(
"kill {$consumerProcessId}");
93 foreach ($this->consumers as $consumer) {
94 if (!$this->getConsumerProcessIds($consumer)) {
95 exec(
"{$this->getConsumerStartCommand($consumer, true)} > /dev/null &");
100 if (file_exists($this->logFilePath)) {
102 unlink($this->logFilePath);
103 if (file_exists($this->logFilePath)) {
105 "Precondition failed: test log ({$this->logFilePath}) cannot be deleted before test execution." 116 foreach ($this->consumers as $consumer) {
117 foreach ($this->getConsumerProcessIds($consumer) as $consumerProcessId) {
118 exec(
"kill {$consumerProcessId}");
129 foreach ($this->consumers as $consumer) {
130 $consumers[$consumer] = $this->getConsumerProcessIds($consumer);
139 private function getConsumerProcessIds($consumer)
141 exec(
"ps ax | grep -v grep | grep '{$this->getConsumerStartCommand($consumer)}' | awk '{print $1}'",
$output);
152 private function getConsumerStartCommand($consumer, $withEnvVariables =
false)
154 $binDirectory = realpath(INTEGRATION_TESTS_DIR .
'/bin/');
155 $magentoCli = $binDirectory .
'/magento';
156 $consumerStartCommand =
"php {$magentoCli} queue:consumers:start -vvv " . $consumer;
157 if ($this->maxMessages) {
158 $consumerStartCommand .=
" --max-messages={$this->maxMessages}";
160 if ($withEnvVariables) {
161 $params = $this->appInitParams;
162 $params[
'MAGE_DIRS'][
'base'][
'path'] =
BP;
163 $params =
'INTEGRATION_TEST_PARAMS="' . urldecode(http_build_query(
$params)) .
'"';
164 $consumerStartCommand =
$params .
' ' . $consumerStartCommand;
166 return $consumerStartCommand;
179 $assertion = call_user_func_array($condition,
$params);
180 }
while (!$assertion && (
$i++ < 180));
192 return $this->publisher;
exec($command, array &$output=null, &$return_var=null)
waitForAsynchronousResult(callable $condition, $params)
__construct(PublisherInterface $publisher, OsInfo $osInfo, Amqp $amqpHelper, $logFilePath, $consumers, $appInitParams, $maxMessages=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]