public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/
@ 2011-05-17 20:56 Zac Medico
  0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2011-05-17 20:56 UTC (permalink / raw
  To: gentoo-commits

commit:     0ea4406a64f8af1143e1a819b61f95e8b1777f99
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue May 17 20:56:15 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue May 17 20:56:15 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0ea4406a

test_asynchronous_lock: test waiting

---
 pym/portage/tests/locks/test_asynchronous_lock.py |   25 +++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py
index 7e9fdfe..e72adf6 100644
--- a/pym/portage/tests/locks/test_asynchronous_lock.py
+++ b/pym/portage/tests/locks/test_asynchronous_lock.py
@@ -37,3 +37,28 @@ class AsynchronousLockTestCase(TestCase):
 
 		finally:
 			shutil.rmtree(tempdir)
+
+	def testAsynchronousLockWait(self):
+		scheduler = PollScheduler().sched_iface
+		tempdir = tempfile.mkdtemp()
+		try:
+			path = os.path.join(tempdir, 'lock_me')
+			lock1 = AsynchronousLock(path=path, scheduler=scheduler)
+			lock1.start()
+			self.assertEqual(lock1.wait(), os.EX_OK)
+
+			# lock2 requires _force_async=True since the portage.locks
+			# module is not designed to work as intended here if the
+			# same process tries to lock the same file more than
+			# one time concurrently.
+			lock2 = AsynchronousLock(path=path, scheduler=scheduler,
+				_force_async=True, _force_process=True)
+			lock2.start()
+			# lock2 should we waiting for lock1 to release
+			self.assertEqual(lock2.returncode, None)
+
+			lock1.unlock()
+			self.assertEqual(lock2.wait(), os.EX_OK)
+			lock2.unlock()
+		finally:
+			shutil.rmtree(tempdir)



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/
@ 2011-05-17 21:03 Zac Medico
  0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2011-05-17 21:03 UTC (permalink / raw
  To: gentoo-commits

commit:     1ffdb3667e18b50e52bbd5c2fa64f5e13a892eb5
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue May 17 21:02:12 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue May 17 21:02:12 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1ffdb366

test_asynchronous_lock: test wait and cancel

---
 pym/portage/tests/locks/test_asynchronous_lock.py |   22 +++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py
index e72adf6..dc4619d 100644
--- a/pym/portage/tests/locks/test_asynchronous_lock.py
+++ b/pym/portage/tests/locks/test_asynchronous_lock.py
@@ -62,3 +62,25 @@ class AsynchronousLockTestCase(TestCase):
 			lock2.unlock()
 		finally:
 			shutil.rmtree(tempdir)
+
+	def testAsynchronousLockWaitCancel(self):
+		scheduler = PollScheduler().sched_iface
+		tempdir = tempfile.mkdtemp()
+		try:
+			path = os.path.join(tempdir, 'lock_me')
+			lock1 = AsynchronousLock(path=path, scheduler=scheduler)
+			lock1.start()
+			self.assertEqual(lock1.wait(), os.EX_OK)
+			lock2 = AsynchronousLock(path=path, scheduler=scheduler,
+				_force_async=True, _force_process=True)
+			lock2.start()
+			# lock2 should we waiting for lock1 to release
+			self.assertEqual(lock2.returncode, None)
+
+			# Cancel lock2 and then check wait() and returncode results.
+			lock2.cancel()
+			self.assertEqual(lock2.wait() == os.EX_OK, False)
+			self.assertEqual(lock2.returncode == os.EX_OK, False)
+			lock1.unlock()
+		finally:
+			shutil.rmtree(tempdir)



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/
@ 2011-05-17 21:14 Zac Medico
  0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2011-05-17 21:14 UTC (permalink / raw
  To: gentoo-commits

commit:     f94e8ce0c0296cc97ae1a080a21d32c8d23ec2e4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue May 17 21:14:20 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue May 17 21:14:20 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f94e8ce0

test_asynchronous_lock: test returncode more

---
 pym/portage/tests/locks/test_asynchronous_lock.py |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py
index dc4619d..d592f4b 100644
--- a/pym/portage/tests/locks/test_asynchronous_lock.py
+++ b/pym/portage/tests/locks/test_asynchronous_lock.py
@@ -23,17 +23,17 @@ class AsynchronousLockTestCase(TestCase):
 						_force_thread=True,
 						_force_dummy=force_dummy)
 					async_lock.start()
-					async_lock.wait()
-					async_lock.unlock()
+					self.assertEqual(async_lock.wait(), os.EX_OK)
 					self.assertEqual(async_lock.returncode, os.EX_OK)
+					async_lock.unlock()
 
 				async_lock = AsynchronousLock(path=path,
 					scheduler=scheduler, _force_async=force_async,
 					_force_process=True)
 				async_lock.start()
-				async_lock.wait()
-				async_lock.unlock()
+				self.assertEqual(async_lock.wait(), os.EX_OK)
 				self.assertEqual(async_lock.returncode, os.EX_OK)
+				async_lock.unlock()
 
 		finally:
 			shutil.rmtree(tempdir)
@@ -46,6 +46,7 @@ class AsynchronousLockTestCase(TestCase):
 			lock1 = AsynchronousLock(path=path, scheduler=scheduler)
 			lock1.start()
 			self.assertEqual(lock1.wait(), os.EX_OK)
+			self.assertEqual(lock1.returncode, os.EX_OK)
 
 			# lock2 requires _force_async=True since the portage.locks
 			# module is not designed to work as intended here if the
@@ -59,6 +60,7 @@ class AsynchronousLockTestCase(TestCase):
 
 			lock1.unlock()
 			self.assertEqual(lock2.wait(), os.EX_OK)
+			self.assertEqual(lock2.returncode, os.EX_OK)
 			lock2.unlock()
 		finally:
 			shutil.rmtree(tempdir)
@@ -71,6 +73,7 @@ class AsynchronousLockTestCase(TestCase):
 			lock1 = AsynchronousLock(path=path, scheduler=scheduler)
 			lock1.start()
 			self.assertEqual(lock1.wait(), os.EX_OK)
+			self.assertEqual(lock1.returncode, os.EX_OK)
 			lock2 = AsynchronousLock(path=path, scheduler=scheduler,
 				_force_async=True, _force_process=True)
 			lock2.start()
@@ -81,6 +84,7 @@ class AsynchronousLockTestCase(TestCase):
 			lock2.cancel()
 			self.assertEqual(lock2.wait() == os.EX_OK, False)
 			self.assertEqual(lock2.returncode == os.EX_OK, False)
+			self.assertEqual(lock2.returncode is None, False)
 			lock1.unlock()
 		finally:
 			shutil.rmtree(tempdir)



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/
@ 2011-05-18 19:46 Arfrever Frehtes Taifersar Arahesis
  0 siblings, 0 replies; 7+ messages in thread
From: Arfrever Frehtes Taifersar Arahesis @ 2011-05-18 19:46 UTC (permalink / raw
  To: gentoo-commits

commit:     36cd3c2b0a932b59ef91b50ad3bc7ba1a2072d75
Author:     Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Gentoo <DOT> Org>
AuthorDate: Wed May 18 19:46:09 2011 +0000
Commit:     Arfrever Frehtes Taifersar Arahesis <arfrever <AT> gentoo <DOT> org>
CommitDate: Wed May 18 19:46:09 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=36cd3c2b

Fix typos in comments.

---
 pym/portage/tests/locks/test_asynchronous_lock.py |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py
index 6e8bc0a..8946caf 100644
--- a/pym/portage/tests/locks/test_asynchronous_lock.py
+++ b/pym/portage/tests/locks/test_asynchronous_lock.py
@@ -56,7 +56,7 @@ class AsynchronousLockTestCase(TestCase):
 			lock2 = AsynchronousLock(path=path, scheduler=scheduler,
 				_force_async=True, _force_process=True)
 			lock2.start()
-			# lock2 should we waiting for lock1 to release
+			# lock2 should be waiting for lock1 to release
 			self.assertEqual(lock2.poll(), None)
 			self.assertEqual(lock2.returncode, None)
 
@@ -79,7 +79,7 @@ class AsynchronousLockTestCase(TestCase):
 			lock2 = AsynchronousLock(path=path, scheduler=scheduler,
 				_force_async=True, _force_process=True)
 			lock2.start()
-			# lock2 should we waiting for lock1 to release
+			# lock2 should be waiting for lock1 to release
 			self.assertEqual(lock2.poll(), None)
 			self.assertEqual(lock2.returncode, None)
 
@@ -104,7 +104,7 @@ class AsynchronousLockTestCase(TestCase):
 			lock2 = AsynchronousLock(path=path, scheduler=scheduler,
 				_force_async=True, _force_process=True)
 			lock2.start()
-			# lock2 should we waiting for lock1 to release
+			# lock2 should be waiting for lock1 to release
 			self.assertEqual(lock2.poll(), None)
 			self.assertEqual(lock2.returncode, None)
 



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/
@ 2011-06-09  0:33 Zac Medico
  0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2011-06-09  0:33 UTC (permalink / raw
  To: gentoo-commits

commit:     c249745ca37f996ef7de51d1be2997e6734d649b
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Jun  9 00:32:56 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Jun  9 00:32:56 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c249745c

Test noblocking locks.

---
 pym/portage/tests/locks/test_lock_nonblock.py |   46 +++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/locks/test_lock_nonblock.py b/pym/portage/tests/locks/test_lock_nonblock.py
new file mode 100644
index 0000000..d5748ad
--- /dev/null
+++ b/pym/portage/tests/locks/test_lock_nonblock.py
@@ -0,0 +1,46 @@
+# Copyright 2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import shutil
+import tempfile
+import traceback
+
+import portage
+from portage import os
+from portage.tests import TestCase
+
+class LockNonblockTestCase(TestCase):
+
+	def testLockNonblock(self):
+		tempdir = tempfile.mkdtemp()
+		try:
+			path = os.path.join(tempdir, 'lock_me')
+			lock1 = portage.locks.lockfile(path)
+			pid = os.fork()
+			if pid == 0:
+				portage.process._setup_pipes({0:0, 1:1, 2:2})
+				rval = 2
+				try:
+					try:
+						lock2 = portage.locks.lockfile(path, flags=os.O_NONBLOCK)
+					except portage.exception.TryAgain:
+						rval = os.EX_OK
+					else:
+						rval = 1
+						portage.locks.unlockfile(lock2)
+				except SystemExit:
+					raise
+				except:
+					traceback.print_exc()
+				finally:
+					os._exit(rval)
+
+			self.assertEqual(pid > 0, True)
+			pid, status = os.waitpid(pid, 0)
+			self.assertEqual(os.WIFEXITED(status), True)
+			self.assertEqual(os.WEXITSTATUS(status), os.EX_OK)
+
+			portage.locks.unlockfile(lock1)
+		finally:
+			shutil.rmtree(tempdir)
+



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/
@ 2011-12-14  9:18 Zac Medico
  0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2011-12-14  9:18 UTC (permalink / raw
  To: gentoo-commits

commit:     b898440e35aa96cd50c74b13d26d5924d2d708ed
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 14 09:17:16 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Dec 14 09:17:16 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=b898440e

tests/locks: save/restore global env state

This ensures that global __PORTAGE_TEST_HARDLINK_LOCKS overrides work
correctly for all tests.

---
 pym/portage/tests/locks/test_asynchronous_lock.py |   12 ++++++++++++
 pym/portage/tests/locks/test_lock_nonblock.py     |    3 +++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py
index c896cb4..49dd10e 100644
--- a/pym/portage/tests/locks/test_asynchronous_lock.py
+++ b/pym/portage/tests/locks/test_asynchronous_lock.py
@@ -43,11 +43,14 @@ class AsynchronousLockTestCase(TestCase):
 		self._testAsynchronousLock()
 
 	def testAsynchronousLockHardlink(self):
+		prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
 		os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
 		try:
 			self._testAsynchronousLock()
 		finally:
 			os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+			if prev_state is not None:
+				os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
 
 	def _testAsynchronousLockWait(self):
 		scheduler = PollScheduler().sched_iface
@@ -81,11 +84,14 @@ class AsynchronousLockTestCase(TestCase):
 		self._testAsynchronousLockWait()
 
 	def testAsynchronousLockWaitHardlink(self):
+		prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
 		os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
 		try:
 			self._testAsynchronousLockWait()
 		finally:
 			os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+			if prev_state is not None:
+				os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
 
 	def _testAsynchronousLockWaitCancel(self):
 		scheduler = PollScheduler().sched_iface
@@ -116,11 +122,14 @@ class AsynchronousLockTestCase(TestCase):
 		self._testAsynchronousLockWaitCancel()
 
 	def testAsynchronousLockWaitCancelHardlink(self):
+		prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
 		os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
 		try:
 			self._testAsynchronousLockWaitCancel()
 		finally:
 			os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+			if prev_state is not None:
+				os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
 
 	def _testAsynchronousLockWaitKill(self):
 		scheduler = PollScheduler().sched_iface
@@ -157,8 +166,11 @@ class AsynchronousLockTestCase(TestCase):
 		self._testAsynchronousLockWaitKill()
 
 	def testAsynchronousLockWaitKillHardlink(self):
+		prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
 		os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
 		try:
 			self._testAsynchronousLockWaitKill()
 		finally:
 			os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+			if prev_state is not None:
+				os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state

diff --git a/pym/portage/tests/locks/test_lock_nonblock.py b/pym/portage/tests/locks/test_lock_nonblock.py
index 914084c..17f854d 100644
--- a/pym/portage/tests/locks/test_lock_nonblock.py
+++ b/pym/portage/tests/locks/test_lock_nonblock.py
@@ -48,9 +48,12 @@ class LockNonblockTestCase(TestCase):
 		self._testLockNonblock()
 
 	def testLockNonblockHardlink(self):
+		prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
 		os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
 		try:
 			self._testLockNonblock()
 		finally:
 			os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+			if prev_state is not None:
+				os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
 



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/
@ 2012-03-28  0:26 Zac Medico
  0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2012-03-28  0:26 UTC (permalink / raw
  To: gentoo-commits

commit:     f7a7a30ee44ced6628163bf33b52b30467d28246
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 28 00:26:17 2012 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Mar 28 00:26:17 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f7a7a30e

LockNonblockTestCase: close_fds tweak

Make consistent with commit 144c23efbb4e9565debad03c13c5bcab833a8336.

---
 pym/portage/tests/locks/test_lock_nonblock.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/pym/portage/tests/locks/test_lock_nonblock.py b/pym/portage/tests/locks/test_lock_nonblock.py
index 17f854d..2ff7b35 100644
--- a/pym/portage/tests/locks/test_lock_nonblock.py
+++ b/pym/portage/tests/locks/test_lock_nonblock.py
@@ -18,7 +18,10 @@ class LockNonblockTestCase(TestCase):
 			lock1 = portage.locks.lockfile(path)
 			pid = os.fork()
 			if pid == 0:
-				portage.process._setup_pipes({0:0, 1:1, 2:2})
+				portage.locks._close_fds()
+				 # Disable close_fds since we don't exec
+				 # (see _setup_pipes docstring).
+				portage.process._setup_pipes({0:0, 1:1, 2:2}, close_fds=False)
 				rval = 2
 				try:
 					try:



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-03-28  0:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-17 21:03 [gentoo-commits] proj/portage:master commit in: pym/portage/tests/locks/ Zac Medico
  -- strict thread matches above, loose matches on Subject: below --
2012-03-28  0:26 Zac Medico
2011-12-14  9:18 Zac Medico
2011-06-09  0:33 Zac Medico
2011-05-18 19:46 Arfrever Frehtes Taifersar Arahesis
2011-05-17 21:14 Zac Medico
2011-05-17 20:56 Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox