github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/overlord/ifacestate/handlers_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package ifacestate_test 21 22 import ( 23 . "gopkg.in/check.v1" 24 25 "github.com/snapcore/snapd/overlord/ifacestate" 26 "github.com/snapcore/snapd/overlord/state" 27 ) 28 29 type handlersSuite struct{} 30 31 var _ = Suite(&handlersSuite{}) 32 33 func (s *handlersSuite) TestInSameChangeWaitChain(c *C) { 34 st := state.New(nil) 35 st.Lock() 36 defer st.Unlock() 37 38 // no wait chain (yet) 39 startT := st.NewTask("start", "...start") 40 intermediateT := st.NewTask("intermediateT", "...intermediateT") 41 searchT := st.NewTask("searchT", "...searchT") 42 c.Check(ifacestate.InSameChangeWaitChain(startT, searchT), Equals, false) 43 44 // add (indirect) wait chain 45 searchT.WaitFor(intermediateT) 46 intermediateT.WaitFor(startT) 47 c.Check(ifacestate.InSameChangeWaitChain(startT, searchT), Equals, true) 48 } 49 50 func (s *handlersSuite) TestInSameChangeWaitChainDifferentChanges(c *C) { 51 st := state.New(nil) 52 st.Lock() 53 defer st.Unlock() 54 55 t1 := st.NewTask("t1", "...") 56 chg1 := st.NewChange("chg1", "...") 57 chg1.AddTask(t1) 58 59 t2 := st.NewTask("t2", "...") 60 chg2 := st.NewChange("chg2", "...") 61 chg2.AddTask(t2) 62 63 // add a cross change wait chain 64 t2.WaitFor(t1) 65 c.Check(ifacestate.InSameChangeWaitChain(t1, t2), Equals, false) 66 }