Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

BEIJING — The timing of North Korea’s recent nuclear test managed, once again, to embarrass its only ally in the diplomatic world: China.

It was particularly unfortunate for China’s president, Xi Jinping. The test took place hours before Xi took the stage as host of the BRICS summit of major emerging economies — a meeting meant to showcase Beijing as a global player.

This was not the first time that North Korea’s leader, Kim Jong Un, has rattled the Chinese leader: Missile tests upstaged at least two other major events for Xi this year.

Russian President Vladimir Putin, Chinese President Xi Jinping and Indian Prime Minister Narendra Modi arrive at the BRICS summit in Xiamen, China on Tuesday. Mark Schiefelbein / Pool via AP

“Obviously, it is an insult to China,” said Cheng Xiaohe, an international politics professor at Beijing’s Renmin University. “Every time … they put China in an awkward situation that turns the conflict between North Korea and the rest of the world into a conflict between China and the U.S.”

As North Korea’s primary patron, China finds itself at the center of the problem. President Donald Trump has repeatedly pressured China to use its leverage to rein in the North. After Sunday’s test, he tweeted that North Korea had become “a great threat and embarrassment to China,” then followed it up with a threat to cut trade with any country doing business with the North.

The United States is considering, in addition to other options, stopping all trade with any country doing business with North Korea. — Donald J. Trump (@realDonaldTrump) 3 September 2017

A spokesperson for China’s Foreign Ministry called Trump’s trade tweet “unacceptable.”

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Yet Pyongyang’s tests and escalating rhetoric have also infuriated Beijing, by calling into question its credibility to control Kim.

Related: Trump Threatens to Stop U.S. Trade With China. Could He?

North Korea has said in public statements that it wants an official end to the Korean War. The conflict was halted by a 1953 armistice but no peace treaty has been signed. It also wants nothing short of full normalization of relations with the U.S. and to be treated with respect and as an equal in the global arena.

Officially, China’s position remains the same: The only solution is for both sides to back down, and for dialogue. But editorials in government-controlled newspapers and academic forums, which typically reflect what the leadership here is thinking, there is a noticeable shift in tone and more hawkish viewpoints are emerging.

“It’s time to get rid of all the emotions and be a thorough realist on the North Korea issue,” wrote current affairs commentator Li Fang on WeChat, the popular social media platform. “Sanctions are not working, and wars are more terrifying than before. … The key is to figure out what to do next.”

The U.S. is already working on drafting tougher sanctions against North Korea. South Korea and Japan are also expected to push the United Nations to impose an oil embargo on the North. Cutting off supplies would effectively cripple the economy and presumably the development of its weapons programs.

China holds the key: It supplies about 80 percent of the North's oil and fuel oil, much of it through the so-called Friendship Pipeline that runs under the Yalu River separating Dandong, China, from Sinuiju, North Korea.

China has resisted the move, even as Kim Jong Un has become arguably the world’s most undesirable neighbor. Beijing has talked of “red lines” before, but fears that outright collapse of the Kim government could trigger a wave of refugees across its border. Longer term, the reunification of the Koreas would place an American ally right at China’s doorstep.

“If Washington and Seoul cannot solve the crisis and instead place China at the forefront of this situation, they will only mess up the peninsula issue,” said an editorial in Monday’s Global Times, a state-run newspaper and website that frequently publishes nationalistic columns on international affairs. “China is the main external victim of the North Korean nuclear crisis,” it added.

Sanctions to this point have been ineffective. North Korea made a point of announcing that all its components for Sunday’s test were “homemade,” implying that it can survive without imports.

Leaders attend the Dialogue of Emerging Market and Developing Countries on the sideline of the BRICS Summit in Xiamen, China on Tuesday. Mark Schiefelbein / Pool via AP

“[North Korea’s] nuclear technology has improved a lot,” said Zhang Liangui, a professor at the Central Party School of the Communist Party of China. “But that’s not the most important. … It is that North Korea is determined to go on a nuclear path to oppose global society.”

Some Chinese academics and scholars say more powerful sanctions could lure North Korea to the negotiating table. Beijing has long supported measures toward ensuring a denuclearized peninsula, though it is expected to use its veto power at the United Nations to prevent isolating the government even further.

“Putin said the sanctions are useless,” said Cheng of Renmin University, referring to the Russian president. “China said that some people stab others in the back under the name of sanctions.”

As for Xi, he did not even mention North Korea in his opening speech at the BRICS summit or at a closing news conference. A condemnation by BRICS leaders was added to a joint communique as point number 44.

Getting a read on China’s opaque leadership is never easy. Public discussion is censored or outright discouraged.

Asked if he was optimistic the crisis could be resolved without conflict, Zhang, the Central Party School professor, paused, then said, “Let’s see how Trump will decide.”