@@ -24,6 +24,7 @@ import (
2424 "strings"
2525 "testing"
2626
27+ "github.com/knative/serving/pkg/apis/serving"
2728 "github.com/knative/serving/pkg/apis/serving/v1alpha1"
2829 serviceresourcenames "github.com/knative/serving/pkg/controller/service/resources/names"
2930 "github.com/knative/serving/test"
@@ -52,18 +53,15 @@ func updateServiceWithImage(clients *test.Clients, names test.ResourceNames, ima
5253 if err != nil {
5354 return err
5455 }
55- newService , err : = clients .Services .Patch (names .Service , types .JSONPatchType , patchBytes , "" )
56+ _ , err = clients .Services .Patch (names .Service , types .JSONPatchType , patchBytes , "" )
5657 if err != nil {
5758 return err
5859 }
59- if newService .Spec .Generation != int64 (2 ) {
60- return fmt .Errorf ("The spec was updated so the Generation should be 2 but it was actually %d" , newService .Spec .Generation )
61- }
6260 return nil
6361}
6462
6563// Shamelessly cribbed from route_test. We expect the Route and Configuration to be ready if the Service is ready.
66- func assertServiceResourcesUpdated (t * testing.T , logger * zap.SugaredLogger , clients * test.Clients , names test.ResourceNames , routeDomain , expectedText string ) {
64+ func assertServiceResourcesUpdated (t * testing.T , logger * zap.SugaredLogger , clients * test.Clients , names test.ResourceNames , routeDomain , expectedGeneration , expectedText string ) {
6765 // TODO(#1178): Remove "Wait" from all checks below this point.
6866 err := test .WaitForEndpointState (clients .Kube , logger , test .Flags .ResolvableDomain , routeDomain , test .EventuallyMatchesBody (expectedText ), "WaitForEndpointToServeText" )
6967 if err != nil {
@@ -75,7 +73,16 @@ func assertServiceResourcesUpdated(t *testing.T, logger *zap.SugaredLogger, clie
7573 if err := test .CheckRevisionState (clients .Revisions , names .Revision , test .IsRevisionReady ); err != nil {
7674 t .Fatalf ("Revision %s did not become ready to serve traffic: %v" , names .Revision , err )
7775 }
78-
76+ logger .Infof ("The Revision will be annotated with the generation" )
77+ err = test .CheckRevisionState (clients .Revisions , names .Revision , func (r * v1alpha1.Revision ) (bool , error ) {
78+ if a , ok := r .Annotations [serving .ConfigurationGenerationAnnotationKey ]; ok {
79+ if a != expectedGeneration {
80+ return true , fmt .Errorf ("Expected Revision %s to be annotated with generation %s but was %s instead" , names .Revision , expectedGeneration , a )
81+ }
82+ return true , nil
83+ }
84+ return true , fmt .Errorf ("Expected Revision %s to be annotated with generation %s but there was no annotation" , names .Revision , expectedGeneration )
85+ })
7986 logger .Info ("The Service's latestReadyRevisionName should match the Configuration's" )
8087 err = test .CheckConfigurationState (clients .Configs , names .Config , func (c * v1alpha1.Configuration ) (bool , error ) {
8188 return c .Status .LatestReadyRevisionName == names .Revision , nil
@@ -163,7 +170,7 @@ func TestRunLatestService(t *testing.T) {
163170 if err := test .WaitForServiceState (clients .Services , names .Service , test .IsServiceReady , "ServiceIsReady" ); err != nil {
164171 t .Fatalf ("The Service %s was not marked as Ready to serve traffic to Revision %s: %v" , names .Service , names .Revision , err )
165172 }
166- assertServiceResourcesUpdated (t , logger , clients , names , routeDomain , "What a spaceport!" )
173+ assertServiceResourcesUpdated (t , logger , clients , names , routeDomain , "1" , " What a spaceport!" )
167174
168175 logger .Info ("Updating the Service to use a different image" )
169176 if err := updateServiceWithImage (clients , names , imagePaths [1 ]); err != nil {
@@ -181,7 +188,7 @@ func TestRunLatestService(t *testing.T) {
181188 if err := test .WaitForServiceState (clients .Services , names .Service , test .IsServiceReady , "ServiceIsReady" ); err != nil {
182189 t .Fatalf ("The Service %s was not marked as Ready to serve traffic to Revision %s: %v" , names .Service , names .Revision , err )
183190 }
184- assertServiceResourcesUpdated (t , logger , clients , names , routeDomain , "Re-energize yourself with a slice of pepperoni!" )
191+ assertServiceResourcesUpdated (t , logger , clients , names , routeDomain , "2" , " Re-energize yourself with a slice of pepperoni!" )
185192}
186193
187194// TODO(jonjohnsonjr): LatestService roads less traveled.
0 commit comments