Skip to content

Commit 117d51b

Browse files
committed
magento-engcom/bulk-api#4 Support for Async operations in WebAPI
- Fixed integration tests
1 parent 34577af commit 117d51b

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

dev/tests/integration/framework/Magento/TestFramework/Helper/Amqp.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\TestFramework\Helper;
76

8-
use Magento\Framework\HTTP\Client\Curl;
7+
declare(strict_types=1);
8+
9+
namespace Magento\TestFramework\Helper;
910

1011
/**
1112
* Helper class to access RabbitMQ server configuration
@@ -62,4 +63,51 @@ public function getExchangeBindings($name)
6263
$data = $this->curl->getBody();
6364
return json_decode($data, true);
6465
}
66+
67+
/**
68+
* Get All available connections
69+
*
70+
* @return array
71+
*/
72+
public function getConnections()
73+
{
74+
$this->curl->get($this->host . 'connections');
75+
$data = $this->curl->getBody();
76+
$data = json_decode($data, true);
77+
$output = [];
78+
foreach ($data as $value) {
79+
$output[$value['name']] = $value;
80+
}
81+
return $output;
82+
}
83+
84+
/**
85+
* @param string $name
86+
* @param int $numMessages
87+
* @return string
88+
*/
89+
public function clearQueue(string $name, int $numMessages = 50)
90+
{
91+
$body = [
92+
"count" => $numMessages,
93+
"ackmode" => "ack_requeue_false",
94+
"encoding" => "auto",
95+
"truncate" => 50000
96+
];
97+
$this->curl->post($this->host . 'queue/%2f/' . $name . '/get', json_encode($body));
98+
return $this->curl->getBody();
99+
}
100+
101+
/**
102+
* Delete connection
103+
*
104+
* @param $name
105+
* @return string $data
106+
*/
107+
public function deleteConnection($name)
108+
{
109+
$this->curl->delete($this->host . 'conections/' . urlencode($name));
110+
$data = $this->curl->getBody();
111+
return $data;
112+
}
65113
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\TestFramework\Helper;
10+
11+
use Magento\Framework\HTTP\Client\Curl as CurlLibrary;
12+
13+
class Curl extends CurlLibrary
14+
{
15+
/**
16+
* Make DELETE request
17+
*
18+
* String type was added to parameter $param in order to support sending JSON or XML requests.
19+
* This feature was added base on Community Pull Request https://github.com/magento/magento2/pull/8373
20+
*
21+
* @param string $uri
22+
* @return void
23+
*
24+
* @see \Magento\Framework\HTTP\Client#post($uri, $params)
25+
*/
26+
public function delete($uri)
27+
{
28+
$this->makeRequest("DELETE", $uri);
29+
}
30+
}

dev/tests/integration/framework/Magento/TestFramework/MessageQueue/PublisherConsumerController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\TestFramework\MessageQueue;
710

811
use Magento\Framework\MessageQueue\PublisherInterface;
912
use Magento\Framework\OsInfo;
13+
use Magento\TestFramework\Helper\Amqp;
1014

1115
class PublisherConsumerController
1216
{
@@ -40,9 +44,15 @@ class PublisherConsumerController
4044
*/
4145
private $appInitParams;
4246

47+
/**
48+
* @var Amqp
49+
*/
50+
private $amqpHelper;
51+
4352
public function __construct(
4453
PublisherInterface $publisher,
4554
OsInfo $osInfo,
55+
Amqp $amqpHelper,
4656
$logFilePath,
4757
$consumers,
4858
$appInitParams,
@@ -54,6 +64,7 @@ public function __construct(
5464
$this->maxMessages = $maxMessages;
5565
$this->osInfo = $osInfo;
5666
$this->appInitParams = $appInitParams;
67+
$this->amqpHelper = $amqpHelper;
5768
}
5869

5970
/**
@@ -69,10 +80,16 @@ public function initialize()
6980
"This test relies on *nix shell and should be skipped in Windows environment."
7081
);
7182
}
83+
$connections = $this->amqpHelper->getConnections();
84+
foreach ($connections as $connectionName => $connectionData) {
85+
$this->amqpHelper->deleteConnection($connectionName);
86+
}
87+
$this->amqpHelper->clearQueue("async.operations.all");
7288
foreach ($this->consumers as $consumer) {
7389
foreach ($this->getConsumerProcessIds($consumer) as $consumerProcessId) {
7490
exec("kill {$consumerProcessId}");
7591
}
92+
7693
}
7794
foreach ($this->consumers as $consumer) {
7895
if (!$this->getConsumerProcessIds($consumer)) {

0 commit comments

Comments
 (0)