~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/tests/test_event.c

  • Committer: Scott James Remnant
  • Date: 2008-06-05 20:31:25 UTC
  • Revision ID: scott@netsplit.com-20080605203125-3gl4ov8g8fv9c71m
* init/event.c (event_finished): Clear jobs referenced in the
blocking list, rather than iterating the entire jobs hash.
(event_finished_handle_jobs): Drop this function.
* init/tests/test_event.c (test_finished, test_finished_handle_jobs):
Merge tests again and test using both the blocking list and job's
blocked member.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1596
1596
{
1597
1597
        JobClass      *class = NULL;
1598
1598
        Job           *job;
1599
 
        Event         *event = NULL;
 
1599
        Event         *event = NULL, *bevent = NULL;
 
1600
        Blocked       *blocked = NULL;
1600
1601
        EventOperator *oper;
1601
1602
 
1602
1603
        TEST_FUNCTION ("event_finished");
1719
1720
 
1720
1721
                nih_free (class);
1721
1722
        }
1722
 
}
1723
 
 
1724
 
void
1725
 
test_finished_handle_jobs (void)
1726
 
{
1727
 
        JobClass *class = NULL;
1728
 
        Job      *job = NULL;
1729
 
        Event    *event = NULL, *blocked = NULL;
1730
 
 
1731
 
        TEST_FUNCTION ("event_finished_handle_jobs");
1732
1723
 
1733
1724
 
1734
1725
        /* Check that a finishing event has no effect on a stopping job
1758
1749
                TEST_EQ (job->state, JOB_STOPPING);
1759
1750
                TEST_EQ_P (job->blocked, NULL);
1760
1751
 
 
1752
                TEST_LIST_EMPTY (&event->blocking);
1761
1753
                TEST_FREE (event);
1762
1754
 
1763
1755
                nih_free (class);
1791
1783
                TEST_EQ (job->state, JOB_STARTING);
1792
1784
                TEST_EQ_P (job->blocked, NULL);
1793
1785
 
 
1786
                TEST_LIST_EMPTY (&event->blocking);
1794
1787
                TEST_FREE (event);
1795
1788
 
1796
1789
                nih_free (class);
1812
1805
                        job->goal = JOB_STOP;
1813
1806
                        job->state = JOB_STOPPING;
1814
1807
 
1815
 
                        job->blocked = event_new (job, "wibble", NULL);
1816
 
                        event_block (job->blocked);
1817
 
                        blocked = job->blocked;
 
1808
                        bevent = event_new (job, "wibble", NULL);
 
1809
                        blocked = blocked_new (bevent, BLOCKED_JOB, job);
 
1810
                        nih_list_add (&bevent->blocking, &blocked->entry);
 
1811
                        event_block (bevent);
 
1812
 
 
1813
                        job->blocked = bevent;
 
1814
 
 
1815
                        TEST_FREE_TAG (blocked);
1818
1816
 
1819
1817
                        nih_hash_add (job_classes, &class->entry);
1820
1818
                }
1823
1821
 
1824
1822
                TEST_EQ (job->goal, JOB_STOP);
1825
1823
                TEST_EQ (job->state, JOB_STOPPING);
1826
 
                TEST_EQ_P (job->blocked, blocked);
 
1824
                TEST_EQ_P (job->blocked, bevent);
 
1825
 
 
1826
                TEST_NOT_FREE (blocked);
 
1827
                TEST_EQ (bevent->blockers, 1);
1827
1828
 
1828
1829
                TEST_FREE (event);
1829
1830
 
1846
1847
                        job->goal = JOB_START;
1847
1848
                        job->state = JOB_STARTING;
1848
1849
 
1849
 
                        job->blocked = event_new (job, "wibble", NULL);
1850
 
                        event_block (job->blocked);
1851
 
                        blocked = job->blocked;
 
1850
                        bevent = event_new (job, "wibble", NULL);
 
1851
                        blocked = blocked_new (bevent, BLOCKED_JOB, job);
 
1852
                        nih_list_add (&bevent->blocking, &blocked->entry);
 
1853
                        event_block (bevent);
 
1854
 
 
1855
                        job->blocked = bevent;
 
1856
 
 
1857
                        TEST_FREE_TAG (blocked);
1852
1858
 
1853
1859
                        nih_hash_add (job_classes, &class->entry);
1854
1860
                }
1857
1863
 
1858
1864
                TEST_EQ (job->goal, JOB_START);
1859
1865
                TEST_EQ (job->state, JOB_STARTING);
1860
 
                TEST_EQ_P (job->blocked, blocked);
 
1866
                TEST_EQ_P (job->blocked, bevent);
1861
1867
 
1862
 
                TEST_EQ (blocked->blockers, 1);
 
1868
                TEST_NOT_FREE (blocked);
 
1869
                TEST_EQ (bevent->blockers, 1);
1863
1870
 
1864
1871
                TEST_FREE (event);
1865
1872
 
1888
1895
 
1889
1896
                        job->blocked = event;
1890
1897
 
 
1898
                        blocked = blocked_new (event, BLOCKED_JOB, job);
 
1899
                        nih_list_add (&event->blocking, &blocked->entry);
 
1900
 
 
1901
                        TEST_FREE_TAG (blocked);
 
1902
 
1891
1903
                        nih_hash_add (job_classes, &class->entry);
1892
1904
                }
1893
1905
 
1901
1913
                waitpid (job->pid[PROCESS_POST_STOP], NULL, 0);
1902
1914
 
1903
1915
                TEST_FREE (event);
 
1916
                TEST_FREE (blocked);
1904
1917
 
1905
1918
                nih_free (class);
1906
1919
        }
1927
1940
 
1928
1941
                        job->blocked = event;
1929
1942
 
 
1943
                        blocked = blocked_new (event, BLOCKED_JOB, job);
 
1944
                        nih_list_add (&event->blocking, &blocked->entry);
 
1945
 
 
1946
                        TEST_FREE_TAG (blocked);
 
1947
 
1930
1948
                        nih_hash_add (job_classes, &class->entry);
1931
1949
                }
1932
1950
 
1940
1958
                waitpid (job->pid[PROCESS_PRE_START], NULL, 0);
1941
1959
 
1942
1960
                TEST_FREE (event);
 
1961
                TEST_FREE (blocked);
1943
1962
 
1944
1963
                nih_free (class);
1945
1964
        }
1958
1977
        test_pending ();
1959
1978
        test_pending_handle_jobs ();
1960
1979
        test_finished ();
1961
 
        test_finished_handle_jobs ();
1962
1980
 
1963
1981
        return 0;
1964
1982
}