knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/test/upgrade/suite_execution.go (about)

     1  /*
     2  Copyright 2020 The Knative Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package upgrade
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func (se *suiteExecution) processOperationGroup(t *testing.T, op operationGroup) {
    24  	t.Run(op.groupName, func(t *testing.T) {
    25  		l := se.configuration.logger(t)
    26  		if len(op.operations) > 0 {
    27  			l.Infof(op.groupTemplate, op.num, len(op.operations))
    28  			for i, operation := range op.operations {
    29  				l.Infof(op.elementTemplate, op.num, i+1, operation.Name())
    30  				if t.Failed() {
    31  					l.Debugf(skippingOperationTemplate, operation.Name())
    32  					return
    33  				}
    34  				handler := operation.Handler()
    35  				t.Run(operation.Name(), func(t *testing.T) {
    36  					handler(Context{T: t, Log: l})
    37  				})
    38  				if t.Failed() {
    39  					return
    40  				}
    41  			}
    42  		} else {
    43  			l.Infof(op.skippingGroupTemplate, op.num)
    44  		}
    45  	})
    46  }
    47  
    48  func (se *suiteExecution) execute() {
    49  	idx := 1
    50  	stopCh := make(chan struct{})
    51  	t := se.configuration.T
    52  	operations := []func(t *testing.T, num int){
    53  		se.installingBase,
    54  		se.preUpgradeTests,
    55  	}
    56  	for _, operation := range operations {
    57  		operation(t, idx)
    58  		idx++
    59  		if t.Failed() {
    60  			return
    61  		}
    62  	}
    63  
    64  	t.Run("Run", func(t *testing.T) {
    65  		// Calls t.Parallel() after doing setup phase. The second part runs in parallel
    66  		// with Steps below.
    67  		se.runContinualTests(t, idx, stopCh)
    68  
    69  		idx++
    70  		// At this point only the setup phase of continual tests was done. We want
    71  		// to quit early in the event of failures.
    72  		if t.Failed() {
    73  			close(stopCh)
    74  			return
    75  		}
    76  
    77  		operations = []func(t *testing.T, num int){
    78  			se.upgradeWith,
    79  			se.postUpgradeTests,
    80  			se.downgradeWith,
    81  			se.postDowngradeTests,
    82  		}
    83  		t.Run("Steps", func(t *testing.T) {
    84  			defer close(stopCh)
    85  			// The rest of this test group will run in parallel with individual continual tests.
    86  			t.Parallel()
    87  			for _, operation := range operations {
    88  				operation(t, idx)
    89  				idx++
    90  				if t.Failed() {
    91  					return
    92  				}
    93  			}
    94  		})
    95  	})
    96  }