Merge lp:~ted/pay-service/verify-after-purchase into lp:pay-service/14.10

Proposed by Ted Gould
Status: Merged
Approved by: dobey
Approved revision: 25
Merged at revision: 21
Proposed branch: lp:~ted/pay-service/verify-after-purchase
Merge into: lp:pay-service/14.10
Diff against target: 172 lines (+53/-27)
6 files modified
libpay/pay-package.h (+2/-1)
service/item-memory.cpp (+9/-15)
service/verification-curl.cpp (+15/-8)
tests/item-memory-tests.cpp (+15/-3)
tests/verification-curl-tests.cpp (+9/-0)
tests/verification-test.h (+3/-0)
To merge this branch: bzr merge lp:~ted/pay-service/verify-after-purchase
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+226728@code.launchpad.net

Commit message

Verify purchase status after running Purchase UI

Description of the change

This makes it so that we always verify the status after each time we run the UI so that we don't have to trust its return code. It also fixes some bugs found with multiple verify calls.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) wrote :

Solves the hang I was seeing in my testing, and does result in verification when the payui exits regardless of exit code.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libpay/pay-package.h'
--- libpay/pay-package.h 2014-06-14 02:56:52 +0000
+++ libpay/pay-package.h 2014-07-14 18:39:31 +0000
@@ -33,7 +33,8 @@
33 * The states that an purchased item can be in.33 * The states that an purchased item can be in.
34 */34 */
35typedef enum35typedef enum
36{ /*< prefix=PAY_PACKAGE_ITEM_STATUS */36{
37 /*< prefix=PAY_PACKAGE_ITEM_STATUS */
37 PAY_PACKAGE_ITEM_STATUS_UNKNOWN, /*< nick=unknown */38 PAY_PACKAGE_ITEM_STATUS_UNKNOWN, /*< nick=unknown */
38 PAY_PACKAGE_ITEM_STATUS_VERIFYING, /*< nick=verifying */39 PAY_PACKAGE_ITEM_STATUS_VERIFYING, /*< nick=verifying */
39 PAY_PACKAGE_ITEM_STATUS_PURCHASED, /*< nick=purchased */40 PAY_PACKAGE_ITEM_STATUS_PURCHASED, /*< nick=purchased */
4041
=== modified file 'service/item-memory.cpp'
--- service/item-memory.cpp 2014-05-30 12:50:42 +0000
+++ service/item-memory.cpp 2014-07-14 18:39:31 +0000
@@ -60,16 +60,16 @@
6060
61 bool verify (void)61 bool verify (void)
62 {62 {
63 if (vitem != nullptr)
64 {
65 return true;
66 }
67 if (!vfactory->running())63 if (!vfactory->running())
68 {64 {
69 return false;65 return false;
70 }66 }
7167
72 vitem = vfactory->verifyItem(app, id);68 if (vitem == nullptr)
69 {
70 vitem = vfactory->verifyItem(app, id);
71 }
72
73 if (vitem == nullptr)73 if (vitem == nullptr)
74 {74 {
75 /* Uhg, failed */75 /* Uhg, failed */
@@ -121,17 +121,11 @@
121121
122 pitem->purchaseComplete.connect([this](Purchase::Item::Status status)122 pitem->purchaseComplete.connect([this](Purchase::Item::Status status)
123 {123 {
124 switch (status)124 /* Verifying on each time the purchase UI runs right now because
125 we're not getting reliable status back from them. */
126 if (!verify())
125 {127 {
126 case Purchase::Item::PURCHASED:128 setStatus(Item::Status::NOT_PURCHASED);
127 setStatus(Item::Status::PURCHASED);
128 break;
129 case Purchase::Item::ERROR:
130 case Purchase::Item::NOT_PURCHASED:
131 default: /* Fall through, an error is same as status we don't know */
132 /* We know we were not purchased before, so let's stay that way */
133 setStatus(Item::Status::NOT_PURCHASED);
134 break;
135 }129 }
136 return;130 return;
137 });131 });
138132
=== modified file 'service/verification-curl.cpp'
--- service/verification-curl.cpp 2014-07-10 21:11:03 +0000
+++ service/verification-curl.cpp 2014-07-14 18:39:31 +0000
@@ -87,25 +87,32 @@
8787
88 ~CurlItem (void)88 ~CurlItem (void)
89 {89 {
90 stopThread();
91
92 curl_easy_cleanup(handle);
93
94 if (curlHeaders != nullptr)
95 {
96 curl_slist_free_all (curlHeaders) ;
97 curlHeaders = nullptr;
98 }
99 }
100
101 void stopThread (void)
102 {
90 stop = true;103 stop = true;
91104
92 if (exec.joinable())105 if (exec.joinable())
93 {106 {
94 exec.join();107 exec.join();
95 }108 }
96
97 curl_easy_cleanup(handle);
98
99 if (curlHeaders != nullptr)
100 {
101 curl_slist_free_all (curlHeaders) ;
102 curlHeaders = nullptr;
103 }
104 }109 }
105110
106 virtual bool run (void)111 virtual bool run (void)
107 {112 {
113 stopThread();
108 transferBuffer.clear();114 transferBuffer.clear();
115 stop = false;
109116
110 /* Do the execution in another thread so we can wait on the117 /* Do the execution in another thread so we can wait on the
111 network socket. */118 network socket. */
112119
=== modified file 'tests/item-memory-tests.cpp'
--- tests/item-memory-tests.cpp 2014-05-08 21:42:53 +0000
+++ tests/item-memory-tests.cpp 2014-07-14 18:39:31 +0000
@@ -180,12 +180,24 @@
180 usleep(50 * 1000);180 usleep(50 * 1000);
181 EXPECT_EQ(Item::Item::Status::NOT_PURCHASED, item->getStatus());181 EXPECT_EQ(Item::Item::Status::NOT_PURCHASED, item->getStatus());
182182
183 /* Assume the purchase UI is a liar */
184 std::string fitemname("falsely-purchased-item");
185 pfactory->test_setPurchase(appname, fitemname, true);
186 auto fitem = store->getItem(appname, fitemname);
187
188 ASSERT_TRUE(fitem->verify());
189 usleep(50 * 1000);
190 ASSERT_TRUE(fitem->purchase());
191 usleep(50 * 1000);
192
193 EXPECT_EQ(Item::Item::Status::NOT_PURCHASED, fitem->getStatus());
194
195 /* Legit purchase with verification */
183 std::string pitemname("purchased-item");196 std::string pitemname("purchased-item");
184 pfactory->test_setPurchase(appname, pitemname, true);197 pfactory->test_setPurchase(appname, pitemname, true);
198 vfactory->test_setPurchase(appname, pitemname, true);
199
185 auto pitem = store->getItem(appname, pitemname);200 auto pitem = store->getItem(appname, pitemname);
186
187 ASSERT_TRUE(pitem->verify());
188 usleep(50 * 1000);
189 ASSERT_TRUE(pitem->purchase());201 ASSERT_TRUE(pitem->purchase());
190 usleep(50 * 1000);202 usleep(50 * 1000);
191203
192204
=== modified file 'tests/verification-curl-tests.cpp'
--- tests/verification-curl-tests.cpp 2014-06-12 20:55:13 +0000
+++ tests/verification-curl-tests.cpp 2014-07-14 18:39:31 +0000
@@ -67,6 +67,15 @@
6767
68 EXPECT_EQ(Verification::Item::Status::NOT_PURCHASED, status);68 EXPECT_EQ(Verification::Item::Status::NOT_PURCHASED, status);
6969
70 /* Verify it can be run twice on the same item */
71 status = Verification::Item::Status::ERROR;
72
73 ASSERT_TRUE(item->run());
74 usleep(20 * 1000);
75
76 EXPECT_EQ(Verification::Item::Status::NOT_PURCHASED, status);
77
78 /* Bad App ID */
70 std::string badappid("bad");79 std::string badappid("bad");
71 auto baditem = verify->verifyItem(badappid, itemid);80 auto baditem = verify->verifyItem(badappid, itemid);
72 ASSERT_NE(nullptr, item);81 ASSERT_NE(nullptr, item);
7382
=== modified file 'tests/verification-test.h'
--- tests/verification-test.h 2014-05-05 18:51:08 +0000
+++ tests/verification-test.h 2014-07-14 18:39:31 +0000
@@ -38,6 +38,9 @@
38 }38 }
3939
40 virtual bool run (void) {40 virtual bool run (void) {
41 if (t.joinable())
42 t.join();
43
41 t = std::thread([this]() {44 t = std::thread([this]() {
42 /* Fastest website in the world */45 /* Fastest website in the world */
43 usleep(10 * 1000);46 usleep(10 * 1000);

Subscribers

People subscribed via source and target branches