mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 18:57:18 +08:00 
			
		
		
		
	service/dap: deflake DAP tests (#2872)
1. change ExpectOutputEventProcessExited to accept -1 exit status, this is a real problem on linux but we don't know how to fix it and we already have a test in proc for it. 2. change TestNoDebug_AcceptNoRequestButDisconnect to be less picky about message ordering, all message orderings seem to be fine, there is no reason to insist on a particular one, since the DAP server is unable to actually produce it deterministically. Fixes #2860
This commit is contained in:
		 Alessandro Arzilli
					Alessandro Arzilli
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							df8c2b37ce
						
					
				
				
					commit
					b3e528e4fb
				
			| @ -150,7 +150,8 @@ const ProcessExited = `Process [0-9]+ has exited with status %s\n` | |||||||
|  |  | ||||||
| func (c *Client) ExpectOutputEventProcessExited(t *testing.T, status int) *dap.OutputEvent { | func (c *Client) ExpectOutputEventProcessExited(t *testing.T, status int) *dap.OutputEvent { | ||||||
| 	t.Helper() | 	t.Helper() | ||||||
| 	return c.ExpectOutputEventRegex(t, fmt.Sprintf(ProcessExited, fmt.Sprintf("%d", status))) | 	// We sometimes fail to return the correct exit status on Linux, so allow -1 here as well. | ||||||
|  | 	return c.ExpectOutputEventRegex(t, fmt.Sprintf(ProcessExited, fmt.Sprintf("(%d|-1)", status))) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (c *Client) ExpectOutputEventProcessExitedAnyStatus(t *testing.T) *dap.OutputEvent { | func (c *Client) ExpectOutputEventProcessExitedAnyStatus(t *testing.T) *dap.OutputEvent { | ||||||
|  | |||||||
| @ -5353,11 +5353,39 @@ func TestNoDebug_AcceptNoRequestsButDisconnect(t *testing.T) { | |||||||
|  |  | ||||||
| 		// Disconnect request is ok | 		// Disconnect request is ok | ||||||
| 		client.DisconnectRequestWithKillOption(true) | 		client.DisconnectRequestWithKillOption(true) | ||||||
| 		client.ExpectOutputEventTerminating(t) | 		terminated, disconnectResp := false, false | ||||||
| 		client.ExpectOutputEventRegex(t, fmt.Sprintf(daptest.ProcessExited, "(-1|1)")) | 		for { | ||||||
| 		client.ExpectTerminatedEvent(t) | 			m, err := client.ReadMessage() | ||||||
| 		client.ExpectDisconnectResponse(t) | 			if err != nil { | ||||||
| 		client.ExpectTerminatedEvent(t) | 				break | ||||||
|  | 			} | ||||||
|  | 			switch m := m.(type) { | ||||||
|  | 			case *dap.OutputEvent: | ||||||
|  | 				ok := false | ||||||
|  | 				wants := []string{`Terminating process [0-9]+\n`, fmt.Sprintf(daptest.ProcessExited, "(-1|1)")} | ||||||
|  | 				for _, want := range wants { | ||||||
|  | 					if matched, _ := regexp.MatchString(want, m.Body.Output); matched { | ||||||
|  | 						ok = true | ||||||
|  | 						break | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 				if !ok { | ||||||
|  | 					t.Errorf("\ngot %#v\nwant Output=%q\n", m, wants) | ||||||
|  | 				} | ||||||
|  | 			case *dap.TerminatedEvent: | ||||||
|  | 				terminated = true | ||||||
|  | 			case *dap.DisconnectResponse: | ||||||
|  | 				disconnectResp = true | ||||||
|  | 			default: | ||||||
|  | 				t.Errorf("got unexpected message %#v", m) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		if !terminated { | ||||||
|  | 			t.Errorf("did not get TerminatedEvent") | ||||||
|  | 		} | ||||||
|  | 		if !disconnectResp { | ||||||
|  | 			t.Errorf("did not get DisconnectResponse") | ||||||
|  | 		} | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user